本文介绍了如何以汇编语言打印字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用NASM在Q Emulator中打印字符串.我的代码如下:

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?

谢谢.

推荐答案

好的,这是您提出的问题

ALRIGHT SO here is a thingamabob to your question

要加载该字符串,必须将其移至 si (不是真的想深入,而只需这样做).接下来,为了将字符加载到寄存器AL中,请使用 lodsb .接下来,我们必须打印它,因此请使用 int 10h mov ah,0Eh . Int 10h处理视频,而ah告诉BIOS打印我们在al(aka lodsb)中拥有的所有内容.接下来,我们必须有一个结尾字符char,这样我们就不会永远循环下去.我个人使用 0x00 ,但是您使用0.在我的情况下,0x00更好,因为您不仅可以使用0,而且0x00不打印任何内容,所以您为什么会需要它?

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

这篇关于如何以汇编语言打印字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 15:57