Simon2215
Simon2215

Reputation: 232

NASM Assembler question marks in console

I have a problem with my NASM program. At the moment I'm trying to connect two strings. That works pretty well, but when I'm write in line 15: mov rsi, msg2 instead of mov rsi, 30h the program prints weird output and I don't know why.

The first print on console window is with mov rsi, msg2 and the second with mov rsi, 30h.

Console output:

simon@simon:~/Projekte/NASM$ bash ./run.sh
Ich verbinde mich mit �`

simon@simon:~/Projekte/NASM$ bash ./run.sh
Ich verbinde mich mit 0

Code:

%include 'functions.asm'

SECTION .data
msg1    db      'Ich verbinde mich mit ', 0h;23
msg2    db      '0';2

SECTION .bss
name:   RESB  255

SECTION .text
global  _start

_start:
  mov     rax, msg1
  mov     rsi, 30h ;so it will work and so   mov     rsi, msg2 not!

  push    rax
  call    strlen
  mov     rdi, rax;rdi ist jetzt die Länge
  pop     rax
  mov     [rax + rdi], rsi;Ursprungsstring + Länge

  call    print
  call    exit

functions.asm

strlen:
  push    rbx;Auf den Stack werfen
  mov     rbx, rax

nextchar:
  cmp     byte [rax], 0
  jz      finished
  inc     rax
  jmp     nextchar

finished:
  sub     rax, rbx
  pop     rbx;Aus dem Stack ziehen
  ret

exit:
  push    rax
  push    rbx
  mov     rax, 1;op code 1
  mov     rbx, 0;0 errors
  int     80h
  pop     rax
  pop     rbx
  ret

printstrlen:;rbx repräsentiert Nachricht, rax die Länge.
  push    rcx
  push    rdx
  push    rax
  push    rbx
  mov     rcx, rbx
  mov     rdx, rax
  mov     rax, 4
  mov     rbx, 1
  int     80h
  pop     rcx
  pop     rdx
  pop     rax
  pop     rbx
  ret

print:
  push    rbx
  mov     rbx, rax
  call    strlen
  call    printstrlen
  pop     rbx
  ret

Thanks you for help.

Best regards

Upvotes: 0

Views: 509

Answers (1)

prl
prl

Reputation: 12435

mov rsi, msg2

loads the address of msg2 into rsi. You want to load the value. Use

movzx rsi, byte [msg2]

Upvotes: 1

Related Questions