프로그래밍[Univ]/하드웨어

[하드웨어] IA-32 Basic operand and operation, flag 실습

Cloud Travel 2012. 5. 18. 12:10

Title Program Template  (lab1.asm)


INCLUDE Irvine32.inc


.data

val1 word 1000h

val2 word 2000h

arrayB byte 10h, 20h, 30h, 40h, 50h

arrayW word 100h, 200h, 300h

arrayD dword 10000h, 20000h, 30000h


.code

main PROC

mov bx, 0A69Bh ; insert 0A69Bh into bx.

movzx eax, bx ; eax = 0000A69Bh

movzx edx, bl ; eax = 0000009Bh

movzx cx, bl         ; cx = 009Bh, tail(4bit) of ecx

mov ax, val1 ; ax = 1000h

xchg     ax, val2 ; ax = 2000h val2 = 1000h

mov val1, ax ; val1 = 2000h

mov al, arrayB ; arrayB value is 10h.

mov bl, [arrayB+1] ; Offset's value that offset of arrayB is plused 1. And it's value mov bl.

mov cl, [arrayB+2] ; same action.

mov dl, [arrayB+3] ; same action.

; check the value in the resgister(eax, ebx, ecx, edx)'s tail two bit.

mov cx, 1 ; cx is one.

sub cx, 1 ; zero flag is one!

mov cx, 0 ; cx is setted zero!

sub cx, 1 ; cx is minus value. sign flag is setted one!

; And "small value - large value" barrow one. Carry flag is setted one! 

mov al, 0FFh ; 255 or -1 

add al, 1 ; if al is 255, then zf = 1, c3 = 1, cf = 1  

mov al, +127 ; sign value. add's last carry value is 0 

add al, 1 ; -128. overflow flag = 1, carry flag = 0, zero flag = 0, sign flag = 1


mov al, -128 ; sign value

sub al, 1 ; overflow flag = 1, carry flag(not borrow) = 0, zero flag = 0, sign flag = 0.

call DumpRegs

   exit

main ENDP


END main