Nasm Assembler
Nasm Assembler
Having issues with assembly?
I am having some issues with getting the length of a variable in assembly.
I am using the nasm assembler and I am still learning so mind me if its something simple.
The code below works great EXCEPT it only prints ONE byte instead of the total length of the inputed value.
Code:
section .data
hello: db ‘Hello world!’, 10
msg: db 0
helloLen: equ $-hello
msgLen: equ $-msg
section .text
global _start
_start:
mov ecx,hello
mov edx,helloLen
call print
mov [msg], ecx
call read
mov ecx,[msg]
mov edx,msgLen
call print
call end
print:
mov eax,4
mov ebx,1
int 80h
ret
read:
mov eax,3
int 80h
ret
end:
mov eax,1
mov ebx,0
int 80h
You’ve defined msgLen as being 1 byte (a 0). That won’t change later in the program. If you want the length of the text you input, get that instead (when you input it – and reserve a word to store the length in).
And unless that 0 is the terminator for hello, it’s
hello: db ‘Hello world!’, 10
helloLen: equ $-hello
msg: db 0
msgLen: equ $-msg
inputLen: dw ;storage for the length of the input string
Assembly Language Tutorial #7 nasm Assembler
