Leon
Leon

Reputation: 1

print string in assembly

section .text
org 100h
push selected
call output
mov ah,4Ch
int 21h

output:
push ebp
mov ebp, esp
sub esp, 4
push ebx
mov ah,0x9
mov dx,[ebp+8]
int 21h
pop ebx
mov esp, ebp
pop ebp
ret
section .data
selected DB "I selected a random number between 0 and 99",0xd,0xa,'$'

I must pass parameters by stack.

The expected output is:

"I selected a random number between 0 and 99" 

, but real output is:

"
═  Я ЪЁ■↔Ё▐☺▲♦K☺▲♦V☺▲♦▲♦☺☺☺ ☻               #♣╓ p♣¶ ↑ p♣        ♣
                                                 h(☺ш♦ ┤L═!fUfЙхfГь♦fS┤      gЛU
═!f[fЙьf]├   I selected a random number between 0 and 99"

Why is this happening?

Upvotes: 0

Views: 4134

Answers (1)

BlackBear
BlackBear

Reputation: 22979

The problem is here:

mov dx,[ebp+8]

it would be ok, but you pushed ebx a few lines above, so [ebp+8] isn't the first parameter anymore, but the returning address (which follows the parameter). The output you are seeing is the "ascii translation" of your program. ;)
Try with [ebp+0ch].

Upvotes: 1

Related Questions