Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Addition and Subtraction                  (AddSubTest.asm)
  2.  
  3. ; Chapter 4 example. Demonstration of ADD, SUB,
  4. ; INC, DEC, and NEG instructions, and how
  5. ; they affect the CPU status flags.
  6.  
  7. .386
  8. .model flat,stdcall
  9. .stack 4096
  10. ExitProcess proto,dwExitCode:dword
  11.  
  12. .data
  13. Rval   SDWORD ?
  14. Xval   SDWORD 26
  15. Yval   SDWORD 30
  16. Zval   SDWORD 40
  17.  
  18. .code
  19. main proc
  20.     ; INC and DEC
  21.     mov ax,1000h
  22.     inc ax      ; 1001h
  23.     dec ax      ; 1000h
  24.  
  25.     ; Expression: Rval = -Xval + (Yval - Zval)
  26.     mov eax,Xval
  27.     neg eax         ; -26
  28.     mov ebx,Yval
  29.     sub ebx,Zval    ; -10
  30.     add eax,ebx
  31.     mov Rval,eax    ; -36
  32.  
  33.     ; Zero flag example:
  34.     mov cx,1
  35.     sub cx,1        ; ZF = 1
  36.     mov ax,0FFFFh
  37.     inc ax          ; ZF = 1
  38.  
  39.     ; Sign flag example:
  40.     mov cx,0
  41.     sub cx,1        ; SF = 1
  42.     mov ax,7FFFh
  43.     add ax,2        ; SF = 1
  44.  
  45.     ; Carry flag example:
  46.     mov al,0FFh
  47.     add al,1        ; CF = 1,  AL = 00
  48.  
  49.     ; Overflow flag example:
  50.     mov al,+127
  51.     add al,1        ; OF = 1
  52.     mov al,-128
  53.     sub al,1        ; OF = 1
  54.  
  55.     invoke ExitProcess,0
  56. main endp
  57. end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement