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

  1. LESSON7 - PROCEDURES AND MACROS
  2.  
  3. in assembly as in pascal,c and basic you have the option of using
  4. procedures, to declare a procedure you do :
  5.  
  6. Proc name "proc" distance (far/near)
  7.  
  8. .
  9. .
  10. .
  11.  
  12. ret
  13. endp ; end proc
  14.  
  15. and to call the proc you type "Call Procname"
  16. the ret must come because you have to return to the exact point
  17. you called the proc from, if you pushed registers and didn't pop them
  18. it might not return to the calling position.
  19.  
  20. sseg segment
  21.   db 10 dup (?)
  22. ends
  23.  
  24. cseg segment
  25. assume cs:cseg,ds:cseg,ss:sseg,es:nothing
  26.  
  27. clearscreen proc near
  28.  
  29. mov ax,0b800h
  30. mov es,ax       ; clear the screen, point to screen
  31. mov di,0
  32.  
  33. mov ax,0
  34. mov cx,2000
  35. rep stosw       ; if don't understand go back to learn
  36.  
  37. ret             ; try to erase this and see what happends
  38.  
  39. endp
  40.  
  41. start :
  42.  
  43. push ds
  44.  
  45. call clearscreen
  46.  
  47. pop ds
  48.  
  49. mov ax,4c00h
  50. int 21h
  51.  
  52. ends
  53. end start
  54. end
  55.  
  56. what is macro, macro is a type of semi procedure, the compiler
  57. will copy the code of the macro into the calling point
  58. and therefore increasing the code size and saving a few cycles.
  59. one problem the macro has is that you can't use labels becase if
  60. you will and call it number of times there will be duplicate labels
  61. and the compiler will return error message.
  62.  
  63. macro declarating :
  64. Macro name "macro" parameters
  65. .
  66. .
  67. .
  68. endm ; end macro
  69.  
  70. to call the macro you just write his name, the parameters
  71. is values to pass
  72.  
  73. sseg segment
  74.   db 10 dup (?)
  75. ends
  76.  
  77. cseg segment
  78. assume cs:cseg,ds:cseg,ss:sseg,es:nothing
  79.  
  80. macro clearscreen amount ; amount is a parameter
  81.  
  82. mov ax,0b800h
  83. mov es,ax       ; clear the screen, point to screen
  84. mov di,0
  85.  
  86. mov ax,0
  87. mov cx,amount
  88. rep stosw       ; if don't understand go back to learn
  89.  
  90. endm            ; go back
  91.  
  92. start :
  93.  
  94. push ds
  95.  
  96. clearscreen 2000 ; the code will be copied to this point
  97.  
  98. pop ds
  99.  
  100. mov ax,4c00h
  101. int 21h
  102.  
  103. ends
  104. end start
  105. end
  106.  
  107. so when you write code you will have to deside what's better for you speed
  108. (not much) or size (it can go up to ....) I usually use procs
  109.  
  110. a problem comes up, what happend if a want to use procs and save them
  111. in another file (like unit,lib) and use them in my code, the next
  112. chapter will disscuss that.