| CS306 | Processing Systems and Structures | J. W. Lockwood |
extern void far MYSUB( int , int ); |
| C Variable Type | # of Bytes |
|---|---|
| char | 1 |
| int, short, near* | 2 |
| long, far* | 4 |
#include <stdlib.h>
#include <stdlio.h>
extern int far MYSUB(int x,int y);
extern void far FXIT();
CSUB(int x,int y) {
return x-y;
}
main() {
int z;
z = CSUB (0x6666,0x2222);
printf("%x\n",z);
z = MYSUB(0x6666,0x2222);
printf("%x\n",z);
FXIT();
} |
CL /c sub.c
|
MYSUB( int x , int y ) { .. } |
| Value | Notes |
|---|---|
| 2222h | Right-most variable pushed first |
| 6666h | Left-most variable pushed last |
| Value | Notes |
|---|---|
| CS | Return Address (FAR) |
| IP |
| Mem | Value | Notes |
|---|---|---|
| [BP+8] | 22 | Right-most parameter |
| [BP+6] | 66 | Left-most parameter |
| [BP+4] | CS | Return Address (FAR) |
| [BP+2] | IP | |
| [BP] | BP' | Old value of BP |
|
CSUB(int x , int y) { int i = 77; ... } |
|
MYSUB PROC NEAR ... SUB SP,2 MOV [BP-2],77 ... MYSUB ENDP |
| Mem | Value | Notes |
|---|---|---|
| [BP-2] | 77 | Local Variable |
_MYSUB
GLOBAL _MYSUB
EXTRN DOSXIT GLOBAL _MYSUB, _FXIT SEGMENT code _MYSUB PUSH BP ; Stack Frame MOV BP,SP PUSH DS ; Save all registers modified MOV AX,CS MOV DS,AX ; Load segment register MOV AX,[BP+6] ; Leftmost Argument (x) SUB AX,[BP+8] ; Rightmost Argument (y) POP DS ; Restore modified registers POP BP ; Restore stack frame RET _FXIT CALL DOSXIT |
NASM -f obj -o mysub.o mysub.asm