PE3) Setting Flags

Set the zero flag, carry flag, and overflow flag.

; Program Name: setting flags
; Program Description:  

.386
.model flat,stdcall
.stack 4096
ExitProcess PROTO, dwExitCode:DWORD

.data
myByte BYTE 10001111b
.code
main PROC
mov eax, 0;
mov ebx, 0;

;1  Copy the value defined by the myByte data definition 
;   into the AX register such that the result is positive.
	movzx ax, myByte

;2  Copy the value defined by the myByte data definition 
;   into the BX register such that the result is negative.
	movsx bx, myByte
	inc bx                  ;makes sure the zero flag is 0 (ZR)
	

;3  Perform an arithmetic operation that causes the zero flag to be set.
;   make sure carry flag is zero(cy)
	sub al, myByte          ;set zero flag
	inc al

;4  Using the value defined by the myByte data definition, add 
;   instructions that cause the carry flag to be set.
	mov al, myByte
	add al, 256-10001111b   ;set carry
	mov al, 1               ;make sure the overflow flag is zero(ov)
	inc al

;5  Using the value defined by the myByte data definition, add 
;   instructions that cause the overflow flag to be set.
	mov al, myByte
	add al, myByte          ;set overflow

INVOKE ExitProcess,0
main ENDP
END main

Show Code