|
From: Frank K. <fbk...@zy...> - 2009-08-11 05:54:52
|
Robert Alegrid wrote:
> Hi,
>
> How do I set or clear the overflow flag? I can save it easily enough, but I don't know how to set or clear it. This is for part of a handler for animation scripts for a Win32 game.
>
> ;-------------------------------------------------------------------------------
> ; void __declspec(naked) __stdcall SetCurrentUnitExFlags(void) {
> SetCurrentUnitExFlags:
> lahf
"lahf" is only going to get the low 8 bits of the flags register, and OF
is bit 11, so you'll have to resort to pushf, manipulate the dword on
stack, and popf, I think. Something like this... (intended to be
"portable")...
Best,
Frank
; manipulate the overflow flag
;
; nasm -f elf flag.asm
; gcc -o flag flag.o
;
; Winders? untested.
; nasm -f win32 --prefix _ flag.asm
; gcc -o flag flag.obj
global main
extern puts
section .bss
buffer resb 36 ; 32 characters + CR + LF + 0 ?
section .data
flagstring db " -NioODITSZ-A-P-C", 0
section .text
main:
nop
pusha
mov al, 127
add al, 1 ; set OF
call showflags
; clear OF
pushf
and dword [esp], ~(1 << 11)
popf
call showflags
; set OF
pushf
or dword [esp], 1 << 11
popf
call showflags
popa
ret
;---------------
;---------------
showflags:
pushf
push flagstring
call puts
add esp, 4
pop eax
mov edi, buffer
call eax2bin
mov byte[edi], 0
push buffer
call puts
add esp, 4
ret
;----------------
;----------------
; ascii binary representation of eax -> string at edi
; returns edi = next position; eax, ecx, edx trashed
eax2bin:
mov edx, eax
mov ecx, 32
.top:
mov al, '0'
rcl edx, 1
adc al, 0
stosb
loop .top
ret
;---------------
|