I use visual studio 2017
Lets say one assembly file named "Factorial.asm" and I break it into two assembly files named "one.asm" and "two.asm":
Factiorial.asm works just fine.
Factorial.asm
.386
.model flat, stdcall
option casemap :none
includelib \masm32\lib\msvcrt.lib
sprintf proto C :vararg
includelib \masm32\lib\user32.lib
MessageBoxA proto :ptr,:ptr,:ptr,:DWORD
includelib \masm32\lib\kernel32.lib
ExitProcess proto :dword
.data
format db "%llu", 13, 10, 0
_title db "Result",13,10,0
.code
main PROC
LOCAL szBuf[9]:byte
mov eax, 15 ; initial value (low-order bits)
xor edx, edx ; initial value's high-order bits are 0
mov ecx, eax ; loop counter
Factorial:
dec ecx ; decrement counter
jz Finished ; when counter == 0, we're done
mov ebx, ecx ; make copy of counter
imul ebx, edx ; high-order bits * multiplier
mul ecx ; low-order bits * multiplier
add edx, ebx ; add high-order product to high-order bits of low-order product
cmp ecx, 1
jg Factorial ; keep looping as long as counter > 1
Finished:
invoke sprintf, addr szBuf, offset format, eax, edx
invoke MessageBoxA, 0, addr szBuf, offset _title, 0
invoke ExitProcess, 0
main ENDP
1)one.asm
2)two.asm
one.asm contains
.386
.model flat, stdcall
option casemap :none
includelib \masm32\lib\msvcrt.lib
sprintf proto C :vararg
includelib \masm32\lib\user32.lib
MessageBoxA proto :ptr,:ptr,:ptr,:DWORD
includelib \masm32\lib\kernel32.lib
ExitProcess proto :dword
.data
format db "%llu", 13, 10, 0
_title db "Result",13,10,0
.code
main PROC
LOCAL szBuf[9]:byte
mov eax, 15 ; initial value (low-order bits)
xor edx, edx ; initial value's high-order bits are 0
mov ecx, eax ; loop counter
Factorial:
dec ecx ; decrement counter
jz Finished ; when counter == 0, we're done
mov ebx, ecx ; make copy of counter
imul ebx, edx ; high-order bits * multiplier
mul ecx ; low-order bits * multiplier
add edx, ebx ; add high-order product to high-order bits of low-order product
cmp ecx, 1
jg Factorial ; keep looping as long as counter > 1
main ENDP
two.asm contains
Finished:
invoke sprintf, addr szBuf, offset format, eax, edx
invoke MessageBoxA, 0, addr szBuf, offset _title, 0
invoke ExitProcess, 0
How would I link these together using masm. Or in other words call lables from separate .asm files?
Use non-scoped labels.
Hi Chris,
Here is a quick demo :
Module1.asm :
.386
.model flat,stdcall
option casemap:none
EXTERN finish:PROC
.data
string db 'This is a test.',0
.code
start:
mov edx,OFFSET string
xor eax,eax
@@:
cmp BYTE PTR [edx],0
je finish
inc edx
inc eax
jmp @b
END start
Module2.asm :
.386
.model flat,stdcall
option casemap:none
PUBLIC finish
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\msvcrt.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\msvcrt.lib
.data
msg db 'String size = %u',0
.code
finish:
invoke crt_printf,ADDR msg,eax
invoke ExitProcess,0
END
Build.bat :
\masm32\bin\ml /c /coff Module1.asm
\masm32\bin\ml /c /coff Module2.asm
\masm32\bin\polink /SUBSYSTEM:CONSOLE /OUT:LabelJump.exe Module1.obj Module2.obj