| UMBC CMSC 211 |
void Swap( int *xp, int *yp )
{
int temp;
temp = *yp;
*xp = *yp;
*yp = temp;
}
| .MODEL | SMALL | ||
| ASSUME | SS:NOTHING | ||
| .CODE | |||
| xp | EQU | DWORD PTR [pb + 4] | ; C parameters are reversed |
| yp | EQU | DWORD PTR [pb + 8] | ; These are far pointers |
| PUBLIC | Swap | ||
| Swap | PROC | ||
| push | pb | ||
| mov | bp, sp | ||
| push | ds | ||
| push | si | ||
| push | di | ; save registers | |
| lds | si, xp | ; ds:si --> x | |
| les | di, yp | ; es:di --> y | |
| mov | ax, ds:[si] | ||
| xchg | ax, es:[di] | ||
| pop | di | ||
| pop | si | ||
| pop | ds | ||
| pop | bp | ||
| ret | ; the caller pops params in C | ||
| Swap | ENDP | ||
| END | |||
| mov | ax, SEG b | ||
| push | ax | ||
| mov | ax, OFFSET b | ||
| push | ax | ||
| mov | ax, SEG a | ||
| push | ax | ||
| mov | ax, OFFSET a | ||
| push | ax | ||
| EXTRN | Swap : NEAR | ||
| call | Swap | ||
| add | sp, 8 |