Article ID: 103725
Article Last Modified on 7/1/2004
// Filename: CMAIN.C
// Compile options needed: /c (and /AL for large model)
#include <stdio.h>
extern void MasmSub (char *, short *, long *);
char charvar = 'a';
short shortvar = 1;
long longvar = 32768L;
void main (void)
{
printf ("%c %d %ld\n", charvar, shortvar, longvar);
MasmSub (&charvar, &shortvar, &longvar);
printf ("%c %d %ld", charvar, shortvar, longvar);
}
; Filename: MASMSUB.ASM
; Assemble options needed for MASM: /MX
; Assemble options needed for ML: /c /Cx
.MODEL small, C ;.MODEL ... C tells the assembler that
.286 ; parameters are pushed from right to left.
.CODE
MasmSub PROC uses si, \
pchar:PTR, \
pshort:PTR, \
plong:PTR
mov si, pchar ;Load SI with the address of the char variable.
mov BYTE PTR [si], "z"
mov si, pshort ;Load SI with the address of the short variable.
add WORD PTR [si], 9
mov si, plong ;Load SI with the address of the long variable.
add WORD PTR [si], 1 ;Increment the low word of the long variable
;by 1.
adc WORD PTR [si+2],0 ;Increment the high word.
ret
MasmSub ENDP
END
; Filename: MASMSUB.ASM
; Assemble options needed for MASM: /MX
; Assemble options needed for ML: /c /Cx
.MODEL large, C ;.MODEL ... C tells the assembler that
.286 ; parameters are pushed from right to left.
.CODE
MasmSub PROC uses es si, \
pchar:PTR, \
pshort:PTR, \
plong:PTR
les si, pchar ;Load ES:SI with the address of the char variable.
mov BYTE PTR es:[si], "z"
les si, pshort ;Load ES:SI with the address of the short
;variable.
add WORD PTR es:[si], 9
les si, plong ;Load ES:SI with the address of the long variable.
add WORD PTR [si], 1 ;Increment the low word of the long variable
;by 1.
adc WORD PTR [si+2],0 ;Increment the high word.
ret
MasmSub ENDP
END
; Filename: MASMSUB.ASM
; Assemble options needed for ML: /c /Cx /coff
.386 ;.MODEL ... C tells the assembler that
.MODEL flat, C ; parameters are pushed from right to left.
.CODE
MasmSub PROC uses esi, \
pchar:PTR, \
pshort:PTR, \
plong:PTR
mov esi, pchar ;Load ESI with the address of the char variable.
mov BYTE PTR [esi], "z"
mov esi, pshort ;Load ESI with the address of the short
;variable.
add WORD PTR [esi], 9
mov esi, plong ;Load ESI with the address of the long variable.
inc DWORD PTR [esi] ;Increment the long variable by 1.
ret
MasmSub ENDP
END
a 1 32768 z 10 32769
Additional query words: 8.00 9.00 mixed language
Keywords: kbhowto kblangc kbcode KB103725