【问题标题】:how to print a 8 bit value in NASM如何在 NASM 中打印 8 位值
【发布时间】:2013-03-15 09:12:20
【问题描述】:

很抱歉打扰我的导师。最近几天我发布了一些问题。他们已经伸出手来帮助我。 通过在 x86 机器上的 Ubuntu11.04 中通过 NASM 工作,最近我发现了另一个工作混乱。它是“我如何打印 8 位值”? 假设我的代码的 sn-p 看起来像:

    section .data
         var db "string"
    section .text
         global main
    main:
         nop
         xor ebx,ebx

         mov dl,byte[var+ebx]
         mov al, dl  ; setting to AL the ASCII character to write
         mov bh, 0   ; setting the page number to 0 (all in the same page)
         mov bl, 7   ; setting to bl the foreground pixel color
         mov ah, 0xE ; INT10 E sub mode --> Write Text in Teletype Mode
         int 10      ; "calling" to the interrupt.

         nop

现在,我只想打印 dl。上面的代码使用了@Shmil The Cat 的提示。它会引发分段错误。我们如何解决这个问题?

提前致谢。

【问题讨论】:

  • 你可以使用 C 运行时函数吗?
  • @ShmilTheCat:不。我知道我也不能在这里使用 PUSH DL 命令。因此,我正在寻求帮助
  • @AntoineMathys:先生您好!我不在dos或windows中工作。我正在开发 Ubuntu 11.04。

标签: assembly x86 nasm


【解决方案1】:

在 linux 上你可以使用 putchar:

        global main
        extern putchar

        section .data
        var db "string"

        section .text
main:
         mov ebx, 0  ; index
         mov dl, [var + ebx]
         push edx
         call putchar
         add esp, 4
         ret

要调用一个需要 char 的函数,您需要输入一个完整的单词。该函数将使用最低有效字节。

【讨论】:

  • 我认为部分问题不在于使用 C 运行时函数...请参阅上面的 cmets
  • @Antoine Mathys:非常感谢您,导师。它解决了我的问题。我真的很感谢你
猜你喜欢
  • 2012-09-22
  • 1970-01-01
  • 2014-02-21
  • 1970-01-01
  • 1970-01-01
  • 2020-06-07
  • 1970-01-01
  • 2015-06-09
  • 2015-08-07
相关资源
最近更新 更多