News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

MASM Appears To Be Multi-Pass Assembler?

Started by Fred Harris, January 07, 2016, 01:04:45 AM

Previous topic - Next topic

Fred Harris

Well, back at this trying to learn.  Had to work on documentation for about 6 weeks, so been away since then :(.

Anyway, from the 2nd program - proc.asm, in the \tutorial\console sub-directory, I changed around the order of the main proc by putting it right after start:, and then calling it.  That worked too.  But in the original program the call main came first, and main proc was after it, and there was no forward declaration of main proc.  So I'm assuming masm must be multi-pass and procedures don't need to be forward declared? 


; C:\Code\MASM\Projects\Demo1>ml /c /coff /Cp proc.asm
; C:\Code\MASM\Projects\Demo1>link /SUBSYSTEM:CONSOLE proc.obj
.486
.model flat, stdcall
option casemap :none

include \masm32\include\windows.inc
include \masm32\macros\macros.asm
include \masm32\include\masm32.inc
include \masm32\include\gdi32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\msvcrt.inc

includelib \masm32\lib\masm32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\msvcrt.lib

.code

start:
  main proc
    print chr$("Hi, I am in the 'main' procedure",13,10)
    ret
  main endp

  call main
  invoke  crt_getchar
  exit
end start

jj2007

Good question. Officially, it's a one-pass assembler, but you can do mov eax, thatvariableinline2000, so either it does two passes, or it leaves a placeholder at the beginning and inserts the proper address later. The Jwasm guys certainly know how they do it (Habran, Nidud, ...).

One observation is that you don't need a PROTO if the invoked proc is above. A two-pass assembler could do that even if the proc was below.

Fred Harris

Thanks for the input jj.  I just discovered something.  That code above is defective.  Its assembling and linking and running, but the ...

invoke  crt_getchar

call is not working.  That's just a call to C Std. Lib.  getchar() in msvcrt.lib.  I hadn't picked up on that before.  To get it to work it has to be exactly like in my demo2 sample from the masm32 download.  In other words, something like this...


; C:\Code\MASM\Projects\Demo1>ml /c /coff /Cp proc.asm
; C:\Code\MASM\Projects\Demo1>link /SUBSYSTEM:CONSOLE proc.obj
.486
.model flat, stdcall
option casemap :none

include \masm32\include\windows.inc
include \masm32\macros\macros.asm
include \masm32\include\masm32.inc
include \masm32\include\gdi32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\msvcrt.inc

includelib \masm32\lib\masm32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\msvcrt.lib

.code
start:
  call main
  invoke  crt_getchar
  exit

  main proc
    print chr$("Hi, I am in the 'main' procedure",13,10)
    ret
  main endp
end start


I just find that organization a little confusing because there is a call to proc main before the symbol main is encountered in the code, and there isn't a prototype.  But when I reverse the order as in my first post it fails at runtime, even if prototyped.

hutch--

Fred,

MASM apart from being a cantankerous old pig is also dumb, it needs to have the prototype read first or it will spit the dummy.