w0051977
w0051977

Reputation: 15807

Assembly language intro

I am relatively new to assembly language. I have found so many tutorials that explain how to create a HelloWorld application using ML64 and MASM32, but none of them explain the program in detail. For example, have a look at the example below, which I found online and does compile (64 bit):

main proc
sub rsp, 68h      ; space for 4 arguments + 16byte aligned stack
xor r9d, r9d        ; 4. argument: r9d = uType = 0
lea r8, [caption]   ; 3. argument: r8  = caption
lea rdx, [text]     ; 2. argument: edx = window text
xor rcx, rcx        ; 1. argument: rcx = hWnd = NULL
call MessageBoxA
xor ecx, ecx        ; ecx = exit code
call ExitProcess
main endp

end

I can follow this through. I understand that there are general purpose registers and segment registers but how do you decide which one's to use. For example, why does 'r8' contain the caption instead of r9? Is there an assembly reference for the WinAPI? I realise this is a basic question. I have chosen the MASM32 tag as this is a general question with a 64 bit example.

Upvotes: 3

Views: 811

Answers (2)

old_timer
old_timer

Reputation: 71536

I suggest a few things, first separate learning assembly language and learning operating system calls. Second dont start with x86 as your first assembly language. Make it the third or fourth or last one you learn. If you feel you must I recommend starting with 8088/8086 and getting a foundation in x86 before diving into what it has become.

arm/thumb/msp430/mico8/avr are all good first, second, third, etc instruction sets, by the second or third (different family) if not the first you will have a good foundation in how computers work. pcemu is not mine I forked a version and stripped out the operating system so it can be used to learn the assembly language. For a few bucks you can get good used copies of the 8088/8086 manual from intel

http://www.amazon.com/gp/product/1555120814

Again, a good foundation to what has become the x86 today.

When all of that is done then start looking at operating system calls from asm...sure you may need a few from asm to get started, printing of some sort for example to see your program running.

Upvotes: 0

jofel
jofel

Reputation: 3405

The Windows x64 calling convention is described for example here.

To know the order of the arguments, look for e.g. MessageBoxA here.

Upvotes: 2

Related Questions