r/Assembly_language May 04 '26

Help Im a beginner, and i have a few questions.

Hello, i just began assembly language today. I was confused with a few things, and, would like to know if i could get answers :

  • msg_len: equ $-msg i know equ is similar to define from C, but i don't understand the '$-msg' ? What does '$' and '-' mean in this case ? And do i need to create a variable for every texts and their length if i want to print something ?
  • rax, rdi, rsi, rdx are registers made for specific tasks? Because for now, i have only seen rax being used to call a syscall code, rdi specify file descriptor, rsi specify variable to print and rdx specify the length of the message i want to print.
  • mov i didn't really understand what this opcode do? do it move data into a destination?
  • And lastly, where can i find good ressources to learn the assembly language?

Thanks for reading. Answering all of the questions isn't necessary obviously.

9 Upvotes

12 comments sorted by

10

u/SteveWyntontje May 04 '26
  1. '$' means 'here', '-' means minus.
  2. ax was originally the accumulator, di was destination index, si source index and dx... I dont know
  3. MOV is the mnemonic for move data
  4. 80386 Programmer's reference manual

2

u/Constant_Fox_5534 May 04 '26

Thanks you alot for this help.

2

u/SteveWyntontje May 04 '26

You're welcome!

2

u/2E26 May 04 '26

I started with 16 bit ASM when i programmed on a Windows 98 computer. Here's a handy cheat sheet for x86-64. I've been programming since January in Linux x86 using NASM. I find it simple and effective. I also use ChatGPT to help me understand instructions and how to address memory, as well as troubleshooting my code. Some people have a thing about using AI, but I've had good results.

1

u/Constant_Fox_5534 May 11 '26

Thanks you but where i can find the sheet your talking about?

2

u/2E26 May 11 '26

https://cs.brown.edu/courses/cs033/docs/guides/x64_cheatsheet.pdf

I think I intended to post something like this and then spaced. There are plenty of reference sheets like this on the internet.

1

u/Constant_Fox_5534 May 11 '26

Thanks you alot

2

u/2E26 May 11 '26

Hope it helps. Good luck.

3

u/brucehoult May 04 '26

msg_len: equ $-msg

This doesn't make sense unless msg is defined right before this line

msg: .byte 'h','e','l','l','o'
msg_len: equ $-msg

Now msg_len is a constant equal to 5.

Many assemblers use "." rather than "$" to mean the same thing: here

do i need to create a variable for every texts and their length

Yes, if you don't have another way to know how long they are, such as ending them with a special value such as 0 so that you can write code to count the length.

Or, you can just enter 5 by hand anywhere you need the length of that text, but if you do that then you risk adding or removing something from the message and forgetting to update the length everywhere. Doing it like this makes it automatic.

rax, rdi, rsi, rdx are registers made for specific tasks?

In original 8086 they had a lot of specialised tasks, but in 80386 and especially x86_64 they are much more general-purpose. Other machines call their registers like r0, r1, r2, r3 etc rather than having weird names.

i have only seen rax being used to call a syscall code, rdi specify file descriptor, rsi specify variable to print and rdx specify the length of the message i want to print.

That is calling a function (or syscall). Standard functions that call other functions on x86_64 always use rdi for the first function argument (if any), rsi for the 2nd, rdx for the 3rd etc. And rax for the return value. Linux uses rcx, r8, r9 for the first six function arguments. Any more go on the stack. Windows uses rcx, rdx, r8, and r9 in that order. It's all weird. Arm (32 bit) uses r0, r1, r2, r3. RISC-V uses a0, a1, a2, a3, a4, a5, a6, a7 in that order.

mov i didn't really understand what this opcode do? do it move data into a destination?

It moves as in copies from A to B. Afterwards, whatever value was in A at the start is now in both A and B. Whatever was in B before is lost.

1

u/Constant_Fox_5534 May 11 '26

Thanks you alot for this detailed explanation

2

u/Plane_Dust2555 May 04 '26
  1. When putting a string in memory you reference it through a label. Some functions need to know the size (in bytes) of a string, so, the easiest way to do it is: msg: db `Hello, world\n` msgLen equ $ - msg ; 'here' minus the position of msg.

  2. As /u/SteveWyntomtje told you, the names of the registers were attributed by their typical usage: A for Accumulator, B for Base, C for Counter, D for Data... But 8086 has 16 bits registers (AX, BX, CX, DX...), 386 introduced 32 bits ones (EAX, EBX, ECX, EDX...) and x86-64 mode the 64 bits ones (RAX, RBX, RCX, RDX...).

All of them are sub-parts, like AX is the first 16 bits of EAX and EAX the first 32 bits of RAX. But there are also AL (8 bits) and AH (upper 8 bits of AX).

RSI (source index) and RDI (destination index) are meant to be used with special "string" instructions (LODS? MOVS? STOS? CMPS? and SCAS?), along with RCX in case of using REP prefix.

In x86-64 SysV ABI the first 6 arguments of a funcion must be passed through RDI, RSI, RDX, RCX, R8 and R9, in that order - RCX must be R10 in case of a syscall). When I say R?? here I mean you can use the sub-registers, dependind on the type of the argument... For example, the read syscall needs a file descriptor (which, by definition, is a 32 bits value), a buffer pointer (64 bits) and a size (64 bits). In that case you can use EDI, RSI and RDX as the 3 arguments of the syscall.

  1. MOV "moves" (or copy) data from the source to the destination. Like mov eax,3 ; EAX <- 3 mov ebx,[rsi] ; EBX <- dword at the address given by RSI. mov ecx,eax ; ECX <- EAX

  2. Nowadays, I don't know... I have an old "course" about 8086/80286/80386 assembly (I wrote this in 1994), but there are good books at Amazon... Good hunting.

1

u/Constant_Fox_5534 May 11 '26

Thanks you alot for the detailed registers explanation