问题
I am trying to print a string in Q Emulator using NASM. My code is as below:
mov bx,HELLO
mov ah, 0x0e
int 0x10
HELLO:
db 'Hello', 0
jmp $
times 510-($-$$) db 0
dw 0xaa55
However when I compile this code, the output that I get is
UU
Can anyone please tel me why this is so? And how to get the required string as output?
Thanks in advance.
回答1:
ALRIGHT SO here is a thingamabob to your question
In order to load the string, you must move it into si (don't really want to go to deep but just do it). Next in order to load a character into the register AL use lodsb. Next, we must print it so use int 10h mov ah, 0Eh. Int 10h handles the video and ah tells BIOS to print whatever we have in al (aka lodsb). Next, we must have an ending loading char so we just don't loop forever. Me personally I use 0x00 however you use 0. 0x00 is much better in my case because not only can u use 0, 0x00 does not print anything so why would u ever need it?
ALRIGHT so we got everything done and going here is the code:
mov si, message ;The message location *you can change this* call print ;CALL tells the pc to jump back here when done print: mov ah, 0Eh ;Set function .run: lodsb ;Get the char ; cmp al, 0x00 ;I would use this but ya know u dont so use: cmp al, 0 ;0 has a HEX code of 0x48 so its not 0x00 je .done ;Jump to done if ending code is found int 10h ;Else print jmp .run ; and jump back to .run .done: ret ;Return message db 'Hello, world', 0 ;IF you use 0x00 ;message db 'Hello, world', 0x00
来源:https://stackoverflow.com/questions/40143596/how-to-print-strings-in-assembly-language