0

I was going through these tutorials -https://www.youtube.com/watch?v=0dLkvasLSlo&list=PLPedo-T7QiNsIji329HyTzbKBuCAHwNFC&index=33 and i wanted to create a procedure in flat assembler. This is what i tried and when i try to emulate it gives me the notification of illegal instruction "proc". Please can anyone help me to fix the code or suggest me where i am doing wrong. Thank you.

fasm

org 100h


proc blue  

mov ax,3
call green 

mov ax,5

ret 
endp 

proc green

mov ax,2
ret 
endp 

3 Answers 3

1

Actually, proc and endp are the names of commonly used macros designed to create a stack frame around a procedural call. In other words, they permit to pass arguments using the stack, create local variables for the procedure also using the stack. Those macros are very useful indeed and improve the readability of your sources if you are used to code in high level languages.

There is an implementation of them in the standard fasm for windows distribution, under the INCLUDE/MACRO folder. Trying to decipher them is a bit daunting, because there is so many things that need to be done in order to comply with the different calling conventions. However, using them is easy and straightforward. Just follow the examples that come with fasm.

1

Referenced youtube tutorials are in Microsoft Macro Assembler (MASM). Not Flat Assembler (FASM). These are two different languages, though share alike syntax.

You'll get an error for both MASM and FASM, because there is no proc instruction for your processor. FASM reads the line

<instruction> <args...>

and tries to search for <instruction> opcode. It shows an error if there is none.

You got confused because proc declaration is actually a macros in both FASM and MASM. But for it to work properly you need to include the right module with its definition. In fasm, you could just write:

include 'MACRO\PROC32.INC'

which is located at %you_fasm_dirctory%\INCLUDE\MACRO\. MASM use similar syntax.

Anyway. There is two common ways to define procedure in any assembler: 1) use raw syntax; 2) use macros.

The raw way is to use labels and to manually set up stack frame with local variables. Then clean it. You should google information. The simplest way is to use macros. It does a lot of work for you.

Check here for FASM solution: http://flatassembler.net/docs.php?article=win32#1.3

0

That's not fasm syntax. fasm does not use proc/endp. Just use a label, such as:

org 100h

blue:
    mov ax,3
    call green 
    mov ax,5
    ret 

green:
    mov ax,2
    ret 
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.