Hi,
I'm trying to take working code and turn it into a procedure using push and [esp] for the parameters... but all my code is doing is printing a blank line. I'm hoping that someone can explain how to push a string onto the stack and get it back as a parameter using [esp] - and how to push a number (string length) on to the stack and get it back using [esp + 4]. Also, I guess I would use 'Add esp, 4' to pop new values off of the stack?
Here's the non-working code:
org 0x100
[section .data]
string db "testing", 13, 10
strlen equ $ - string
message db "This is a message", 13, 10
messagelength equ $ - message
[section .text]
push word [string] ; Problem here?
call printstring
push word [message] ; Problem here?
call printstring
mov ax, 0x4c00
int 0x21
printstring:
lea si, [esp] ; Problem here?
xor bx, bx
strtoconsole:
lodsb
inc bx
cmp bx, strlen ; want to use [esp + 4] here.
je quit
mov dl, al
mov ah, 0x06
int 0x21
jmp strtoconsole
quit:
ret
... and here's the code that works:
org 0x100
[section .data]
string db "testing", 13, 10
strlen equ $ - string
message db "This is a message", 13, 10
messagelength equ $ - message
[section .text]
call printstring
mov ax, 0x4c00
int 0x21
printstring:
lea si, [string]
xor bx, bx
strtoconsole:
lodsb
inc bx
cmp bx, strlen
je quit
mov dl, al
mov ah, 0x06
int 0x21
jmp strtoconsole
quit:
leave
ret
If you have any problems understanding what I'm asking (I'm not feeling too clearheaded) I can make it clearer with some comments and rephrasing my question.
Thanks for your time,
Dominick