繁体   English   中英

汇编语言格式存在巨大问题

[英]Having huge problems in assembly language Format

我正在尝试学习汇编语言,但我必须花费十几个小时才能在具有nasm的英特尔酷睿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

请提供帮助,因为书籍仅以更高版本提供。

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

请参阅有关asm语法的Wikipedia中的几个示例,并参阅MASM / NASM差异以及其中提到的链接以获取提示。

其实......我觉得第二个是NASM语法也(!!!)。 我认为“ io.mac”是已故的Sivarama Dandamudi博士的作品。 我拥有的版本适用于Linux(无法在Windows 7上运行),但是它看起来像是较早的版本-可能适用于DOS(“ stack”声明是小费)-这些天,OS告诉我们堆栈在哪里是,我们不知道它)。 Windows 7是否运行DOS? 如果您的第一个示例运行了,那就可以了。 如果没有,请查看名为“ DosBox”的仿真器。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM