Reputation: 127
in MASM, you have IF,WHILE,INVOKE and etc. , which in other assemblers like NASM or TASM:
IF
=CMP
, INVOKE
= push
parameters and call
function , loops(like WHILE
) = CMP
and JMP
to LABELS
, and so on....
So I don't understand, If i'm writing IF
in MASM, it's tanslated to CMP
when I Build the program(assemble&link)? the loops are translated to CMP
and JMP
to some LABLES
? The INVOKE
is translated to push
parameters and call
the function? Basically what Im asking is, if im using IF
WHILE
INVOKE
and so on, They translated to what written here:https://en.wikipedia.org/wiki/X86_instruction_listings or they are compiled like those basic commands.
Because for example, I wrote a simple chat, and this is the socket part:
invoke socket,AF_INET,SOCK_STREAM,IPPROTO_TCP
.IF eax==INVALID_SOCKET
invoke crt_printf,offset Socketerror,offset formatMessagePRINT
WSAGetLastErrorMACRO
jmp End_Program
.else
mov [ListenSocket],eax
invoke crt_printf,offset SocketSuccess,offset formatMessagePRINT
.ENDIF
As you can see, It is look like a code that written in high level programming language. and this is not what I wanted. I want to write programs in assembly in the lowest level that can be written.
So how to write in 32 BIT Assembly in the lowest level that can be written? Do I need to write with the basic commands of 16 bit Assembly (https://en.wikipedia.org/wiki/X86_instruction_listings) and not IF WHILE INVOKE and so on..? this is the only things that I need to stop doing?
Upvotes: 2
Views: 256
Reputation: 4360
If i'm writing IF in MASM, it's tanslated to CMP when I Build the program(assemble&link)?
Yes. For example:
.IF ax==1
MOV bx,2
.ELSE
MOV bx,0
MOV cx,2
.ENDIF
Is assembled to:
00401006 CMP AX,1
0040100A JNZ SHORT 00401012
0040100C MOV BX,2
00401010 JMP SHORT 0040101A
00401012 MOV BX,0
00401016 MOV CX,2
Those high level constructs are here to help with size and readability when the program becomes complex.
The invoke part is also translated to CALL and PUSH and this macro comes in handy in complex programs like the chat you mentionned.
However, using that high level assembly syntax will make it hard to port the code to another assembler since only MASM uses it.
So how to write in 32 BIT Assembly in the lowest level that can be written?
Just write plain assembly? MASM doesn't force you to use .IF and INVOKE. There are loads of tutorials that explain how to do that.
You can alternatively compile your chat program and decompile it to see what was generated by MASM.
Upvotes: 2