Click to See Complete Forum and Search --> : Will this code set and clear zero and sign flags
joblaise
January 29th, 2005, 09:23 PM
I'm a beginning and am having problems with this code. I think my problem is with my data statement. Please provide help. Here's the code:
.data
.386
.model flat, stdcall
option casemap :none ; case sensitive
.code
main PROC
mov cl,1 ; CL=1
sub cl,1 ; CL=0, SF=0, ZF=1
call DumpRegs
sub cl,1 ; CL=-1, SF=1, ZF=0
call DumpRegs
add ch,1 ; CH=0, SF=0, ZF=1
call DumpRegs
add ch,1 ; CH=1, SF=0, ZF=0
call DumpRegs
exit
main ENDP
END main
NoHero
January 30th, 2005, 09:10 AM
To manipulate the CPU flags you can use the pushf and popf functions. The push and pop the flag register onto the stack. With that you can retrieve the flags modify them and set them back.
pushf
pop ax
; Now modify them, they are in ax
push ax
popf
/ 10 posts to go
joblaise
January 30th, 2005, 12:46 PM
Thanks for the response. I see that you used an alternative method, which is good to know. However, I was wondering if the code I wrote could be used, and if so, what am I doing wrong to make it execute properly?
Thanks in advance for your help.
OReubens
January 30th, 2005, 07:10 PM
Thanks for the response. I see that you used an alternative method, which is good to know. However, I was wondering if the code I wrote could be used, and if so, what am I doing wrong to make it execute properly?
Thanks in advance for your help.
Well, you never set CH to anything, so the call
add ch,1 ; CH=0, SF=0, ZF=1
call DumpRegs
Will not do as you think (not what's in the comment).
I'm guessing you wanted to use CL instead of CH.
You can also manipulate set flags via
- SAHF (sotre AH into flags). This will only modify the lower 8 bits of the flags. 'extended' 32bit flags won't be changed.
Direction, interupt enable, Carry flags can be set/cleared directly via CLD/STD, CLI/STI, CLC/STC
codeguru.com
Copyright WebMediaBrands Inc., All Rights Reserved.