NASM - The Netwide Assembler
NASM Forum => Programming with NASM => Topic started by: mk8 on May 01, 2014, 06:58:55 PM
-
Hi, this post might be very poor, but I cant find it anywhere so I decided to ask here, if this question is really bad, just deleted this topic. I just started with nasm and I am able to print string what I need in this way
section .bss
section .data
string: db "some string",0
string_l: equ $-string
section .text
global _start
_start:
mov eax, 4
mov ebx, 1
mov ecx, string
mov edx, string_l
int 80h
mov eax, 1
mov ebx, 0
int 80h
But I am try to display only first character, I tried [string+1].
And what if I wanted to display N element of string?
Thanks a lot!
-
sys_write will print the number of characters in edx, so if you want just one character, tell edx 1.
"[string + 1]" would refer to the second byte of "string", but ecx wants the address, not "[contents]"...
lea ecx, [string + 1]
would do it.
If you want it in a register...
section .bss
section .data
string: db "some string",0
string_l: equ $-string
N dd 6 ; might use a more meaningful name,,,
section .text
global _start
_start:
mov esi, [N] ; or get it some other way
mov eax, 4 ; sys_write
mov ebx, 1 ; sdtout
lea ecx, [string + esi]
mov edx, 1 ; just one, please
int 80h
mov eax, 1 ; sys_exit
mov ebx, 0 ; claim "no error"
int 80h
(untested)
The "stupid" question is one you need to know the answer to but don't ask. :)
Best,
Frank
-
Thank you very much for this reply!
I get it now, once again thank you ;)