2013-10-06 40 views
0

我正在嘗試學習彙編語言,但我必須花費十幾個小時才能在我的英特爾核心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 

請幫書本與後來的格式來只。

+0

_「它總是給出錯誤」_。這並沒有告訴我們任何事情。請詳細說明您收到的錯誤。 – Michael

回答

0

其實......我認爲第二個是Nasm語法也是(!!!)。我認爲「io.mac」是已故博士Sivarama Dandamudi的作品。我得到的版本是針對Linux的(它不能在Windows 7上運行),但是這看起來像一個早期的版本 - 可能用於DOS(「堆棧」聲明是反饋 - 現在操作系統告訴我們堆棧的位置是,我們不告訴它)。 Windows 7是否運行DOS?如果你的第一個例子運行,它會。如果不是,請查看名爲「DosBox」的模擬器。

當您嘗試組裝/鏈接/運行第二個示例user2852570時,會發生什麼?我們可能能夠讓你得到更多的信息.​​.....只要你有Dr. Dandamudi的「io.mac」和「io.o」......