开发者

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]开发者_StackOverflow中文版├   I selected a random number between 0 and 99"

Why is this happening?


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].

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜