Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I don't understand these assembly code and machine code differences if assembly code instructions are equivalent of machine code instructions

Some people say that assembly language = machine language, just that we use mnemonics in assembly language.

After reading Petzold's "CODE", I can't still understand how some of the assembly codes are translated into machine code.

For example (from Tutorials Point's Assembly Course):

_start:             ;tells linker entry point
   mov  edx,len     ;message length
   mov  ecx,msg     ;message to write

section .data
msg db 'Hello, world!', 0xa  ;our dear string

What I understand is that msg contains "Hello, world!" and it's moved into ECX.

But as I know, in x86 the ECX can just store 32 bits.

Then how can we move "Hello, world!" - which is more than 32 bits - into ECX?

And what is the equivalence of that part

section .data
msg db 'Hello, world!', 0xa  ;our dear string

in machine code?

like image 492
Coder88 Avatar asked Sep 01 '25 01:09

Coder88


1 Answers

With msg db you define address containing the string sequence of bytes. With mov ecx, msg you load just this address not its content. Then it's possible to load string by loading [ecx], [ecx+1] etc.

.data defines program section. .text usually contains machine code, .data modifiable program code. There can be more of them such as exception handling labels etc.

like image 185
Zbynek Vyskovsky - kvr000 Avatar answered Sep 03 '25 23:09

Zbynek Vyskovsky - kvr000