Question

I'm having a bad time figuring out how to print a char from a DB string. So let's say I have

str1 DB "hello"
tmp DB ?

and I want to print the 'e' char.

mov ah, [str1 +1*1]
mov tmp, ah
Invoke StdOut, addr tmp

However, this code prints me nothing. I want to know what I'm doing wrong. Thank you!

Was it helpful?

Solution

You've only got a single byte defined for the address (both in tmp and by using ah). This isn't going to work in Windows (which I'm assuming is your desired platform given the masm32 tag and the Invoke). Address should be 16-bit at a bare minimum, and would be 32 or 64 bit in modern versions of Windows.

OTHER TIPS

str1 db 'hello',0      ;6 Bytes
tmp dd 0               ;DWORD

...

mov esi,offset str1    ;ESI = Source
mov edi,offset tmp     ;EDI = Destination
inc esi                ;Skip first letter
lodsb                  ;Load byte from ESI to AL
stosb                  ;Store AL in EDI
invoke StdOut,addr tmp ;Output

You have to build your code as a console-application. Otherwise you wont get printed anything. See your project/build options.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top