Procedures – defined by PROC and ENDP directives. This is called by a CALL instruction and returns to the calling program by executing a RET instruction
Format of PROC and ENDP directives
a. For PROC directive Name PROC type
b. For ENDP directive Name ENDP
Format of a Procedure
a. Prefaced by explanatory comments
b. Save and restore all the registers
c. Must end with a RET instruction
For Calling a procedure, we use CALL instruction (format: CALL address)
For returning to a calling program, we use RET Instruction (format: RET)
Passing Parameters – procedures communicate by sending data items back and forth.
Input and Output parameter – is defines as the data items
Methods for Passing Parameters
a. Passing Parameters in Register – used when passing a small number of parameters
b. Passing Input Parameters by using the Stack – use the BP register to access the parameters in the stack
Arithmetic Numbers
a. Fixed-point number – decimal point is fixed in one position (whole number).
This can be:
1. Unsigned – represents only positive values and zero (0 to 255 for byte)
2. Signed – represents positive and negative values and zero (-128 to 127 for byte)
b. Floating-point number (represent values that have a fractional components)
Main processor – work with fixed-point numbers only
Math co-processor – works with floating-point numbers
Arithmetic Operations
a. Add x1, x2 (add x2 and x1, the sum is stored at x1)
b. Sub x1, x2 (subtract x2 from x1 [x1-x2], difference is stored at x1)
c. MUL (for unsigned) and IMUL (for signed) – assumes that the second operand is in AL or AX
Format: MUL x1 ; assumes x2 is at AX or AL
d. DIV (for unsigned) and IDIV (for sgined) - assumes that the second operand is in AL or AX
We use CBW for adding/subtracting a word and a byte specifically for SIGNED word
We use ADC for accounting the carry from the previous addition (add with carry)
We use SBB for accounting the borrow from the precious subtraction
Decimal Numbers – store values in base 10.
Two ways of storing decimal values
a. Unpacked decimal numbers – each decimal digit is stored in its own byte. We usually use AAA or ASCII adjust for addition
b. Packed decimal numbers – two decimal digits are stored in each byte. We use DAA or decimal adjust for addition
Function Calls – the services provided by DOS interrupt number 21h
DOS
Function calls to do I/O
|
||
Handle
|
Use
|
Default
Device
|
0000h
|
Standard
input
|
Keyboard
|
0001h
|
Standard
output
|
Monitor
|
0002h
|
Standard
error
|
Monitor
|
0003h
|
Standard
auxiliary
|
First
Serial Device
|
0004h
|
Standard
printer
|
Printer
|
No comments:
Post a Comment
Thanks for Suggestion / Comment!
God Bless!