home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / CTFASMTT.ZIP / LESSON5.DOC < prev    next >
Text File  |  1994-10-30  |  3KB  |  99 lines

  1. LESSON5 - FLAGS AND JUMPS
  2.  
  3. in the last chapter we talked about fixed points and their limitations
  4. (assembly has integers you just have to give them neg value)
  5. of shr,shl,ror,rol and the need to detect zero so what we have is
  6. flags, 16 bit register the each bit is a different status of something
  7. that happed.
  8. major flags :
  9.  
  10. CF  - Carry flag is set when there is a borrow in some command lets say
  11.       "sub ax,13" and ax is 21 so a borrow will apear.
  12. PF  - Parity flag is set when the LSB of the operation is even,
  13.       lets say "add ax,11" and ax is 11 so the flag will be set (even)
  14. ZF  - Zero flag is set when the operation is zero lets say "dec ax" and ax
  15.       is now 0 so ZF will be set.
  16. OF  - Overflow flag is set when the operation is beyond the limitation of
  17.       the register lets say "add ax,65535" (ax=100) so the flag will be
  18.       set.
  19.  
  20. there are more flags but much of them aren't used so (if you want to know
  21. open a book or norton guides to assembler)
  22.  
  23. now before anything else a most important command is :
  24.  
  25. CMP register,value - Compare a register to a certain value and set all
  26.                      needed flags.
  27.  
  28. lets say "cmp ax,0" and ax is 0 so the ZF will be set.
  29.  
  30. but (you may ask) how do we use those flags well the answer is
  31. conitional jumps !!
  32.  
  33. JNE  - Jump if not equal
  34. JZ   - Jump if zero
  35. JE   - Jump if equal
  36. JB   - Jump if below
  37. JA   - Jump if above
  38. JAE  - Jump if above and equal
  39. JBE  - Jump if below and equal
  40. JC   - Jump if carry
  41. JNC  - Jump if not carrt
  42. JS   - Jump if sign
  43. JNS  - Jump if not sign
  44. JMP  - Unconditional jump
  45.  
  46. note : all of these conditional jumps (not jmp) can jump only in the range
  47. of near (256/0ffh bytes) and only jmp can jump to the entire code !!!
  48. use - JMP label
  49.  
  50. example :
  51.  
  52. mov ax,10
  53. mov cx,20
  54. mov dx,0
  55.  
  56. div cx           ; does 10/20 result is 0 (if you don't know that so go back
  57.                  ; and repeat the commands.
  58.  
  59. cmp ax,0         ; is ax 0
  60. jz @iszero       ; then it is so jump to label
  61.  
  62. mov cx,ax
  63. mov dx,0
  64. div cx           ; it will never reach it cause it will never be larger then
  65.                  ; zero (if you comment the jz so you will get divide by 0)
  66.  
  67. @iszero :        ; this is a label the "@" before the label is optional
  68.  
  69. mov ax,4c00h     ; terminate
  70. int 21h
  71.  
  72. now lets get back to our fixed points that we want to convert :
  73.  
  74. mov ax,100       ; our circle radios
  75. mov cx,181       ; 181/256 is 0.707 (sin(45))
  76. mul cx           ; multiply (result : 18,100)
  77.  
  78. cmp ax,0         ; is ax 0
  79. jb @neg1         ; jmp below so if neg jump to label
  80.  
  81. shr ax,8
  82. jmp @done        ; don't want to get with the div
  83.  
  84. @neg1 :
  85.  
  86. mov dx,0
  87. mov cx,256
  88. idiv cx          ; ax/256 just use idiv it's a div for integers
  89.  
  90. @done :
  91.  
  92. mov ax,4c000h    ; terminate
  93. int 21h
  94.  
  95. so that's about it in jumps and flags, I sugest that you will train a bit
  96. about all the stuff that you have learned in those chapters cause
  97. it is very important to understand those (those are the needed basic)
  98. in the next chpaters we will start transfering memory blocks,
  99. and use graphics.