【问题标题】:Having huge problems in assembly language Format汇编语言格式存在巨大问题
【发布时间】:2013-10-13 08:34:33
【问题描述】:

我正在尝试学习汇编语言,但我必须花费十几个小时才能在我的带有 nasm 的 intel core i5 win 7 笔记本电脑上运行 .asm 代码。 问题是大多数汇编代码书籍中都有.Section,.Data。当我编译它时,它总是出错,即使它是hello world rogram。

运行的程序(nasm)

org 100h
mov dx,string
mov ah,9
int 21h
mov ah,4Ch
int 21h
string db 'Hello, World!',0Dh,0Ah,'$'

这种格式的程序不能运行

%include  "io.mac"
.STACK 100H
.DATA
number_prompt  db  "Please type a number (<11 digits): ",0
out_msg        db  "The sum of individual digits is: ",0

.UDATA
number         resb  11

.CODE
        .STARTUP
        PutStr  number_prompt  ; request an input number
        GetStr  number,11    ; read input number as a string
        nwln
        mov     EBX,number   ; EBX = address of number
        sub     DX,DX        ; DX = 0 -- DL keeps the sum
repeat_add:
        mov     AL,[EBX]     ; move the digit to AL
        cmp     AL,0         ; if it is the NULL character
        je      done         ;  sum is done
        and     AL,0FH       ; mask off the upper 4 bits
        add     DL,AL        ; add the digit to sum
        inc     EBX          ; update EBX to point to next digit
        jmp     repeat_add   
done:
        PutStr  out_msg
        PutInt  DX           ; write sum
        nwln
        .EXIT

请提供帮助,因为书籍仅具有较新的格式。

【问题讨论】:

  • “总是报错”。这并不能真正告诉我们任何事情。请具体说明您遇到的错误。

标签: assembly


【解决方案1】:

您遇到的错误是因为不同的汇编程序使用不同的语法。你的第一个程序是 NASM 格式;第二个是 MASM 格式。

查看wikipedia on asm syntax 了解几个示例,并查看MASM/NASM Differences 和其中提到的链接以获取提示。

【讨论】:

    【解决方案2】:

    实际上...我认为第二个也是 Nasm 语法(!!!)。我认为“io.mac”是已故 Sivarama Dandamudi 博士的作品。我得到的版本是用于 Linux 的(不能在 Windows 7 上运行),但这看起来像一个早期版本——可能是用于 DOS 的(“堆栈”声明是提示——这些天操作系统告诉我们堆栈在哪里是,我们不告诉它)。 Windows 7 是否运行 DOS?如果您的第一个示例运行,它会运行。如果没有,请查看一个名为“DosBox”的模拟器。

    当您尝试组装/链接/运行第二个示例 user2852570 时,究竟会发生什么?如果您有 Dandamudi 博士的“io.mac”和“io.o”,我们或许可以为您提供更多信息...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-17
      • 2010-10-09
      • 1970-01-01
      • 1970-01-01
      • 2018-08-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多