NASM Forum > Programming with NASM

Confusion about labels

(1/1)

clem55:
Hi. I'm new to assembly programming.

I have a question about labels.


--- Code: ---section .text
global _start
_start:
nop
.again:
call _writeHello
jmp .again

_writeHello:
mov eax, 4
mov ebx, 1
mov ecx, buf
mov edx, len
int 0x80
ret

section .data

buf: db 'Hello World!', 10
len: equ $-buf
--- End code ---

If I assemble this code and them use gdb to disassemble the _start procedure, the following output is produced:

--- Quote ---(gdb) disassemble _start
Dump of assembler code for function _start:
   0x08048080 <+0>:   nop
End of assembler dump.

--- End quote ---

which implies that the function _start ends at the nop instruction, before the .again label. Why does this happen? I was expecting that call and jmp instructions to be included in the _start procedure. Do labels mark the ending of the previous function and beginning of another?

What's the correct code to mark a particular address in the code to jump to later?

Thank You.

Frank Kotler:

--- Quote ---What's the correct code to mark a particular address in the code to jump to later?

--- End quote ---

Labels. I don't think you're confused about labels - you seem to be using them correctly. You might be confused about gdb (I know I am!), or gdb might be confused about labels. An observation: gdb seems not to like Nasm's "local label" syntax - if we use a '.', gdb seems to think we're using a structure. It recognizes ".again:" as a label (apparently), but:


--- Code: ---(gdb) disassemble .again

--- End code ---

gives a syntax error. Okay, the "true name" of that label would be "_start.again"...


--- Code: ---(gdb) disassemble _start.again

--- End code ---

"Attempt to extract a component of a value that is not a structure"

So I guess the "workaround" is: "You can use local labels, but don't expect to tell gdb about 'em."


--- Code: ---(gdb) help disassemble

--- End code ---

gives a reference to "frame". I added a "stack frame" ("enter 0, 0" and "leave") to your "_writeHello" function - didn't seem to help (I added some unreachable code after "ret", and gdb disassembles it). Also mentions "two arguments are taken as a range of memory to dump"...


--- Code: ---disassemble _start _writeHello

--- End code ---

Seems to do what you were expecting. My definition of "function" would be "up until the 'ret'", but gdb seems to consider "function" to mean "from one label to the next". That's my current understanding, at least. More information welcome!

You know that old Otis Redding tune "Hard to Handle"? I think it's about gdb! :)

Best,
Frank

Navigation

[0] Message Index

Go to full version