0

i am trying to learn assembly language but I have to spent a dozen of hours to get a .asm code run on my intel core i5 win 7 laptop with nasm. the problem is most books of assembly code have .Section,.Data in it.and when i compile it it always give error,no matter even it is hello world rogram.

program which run (nasm)

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

program with this format dont run

%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

please help as books come only with later format.

us2012
  • 16,083
  • 3
  • 46
  • 62
shivam_b
  • 21
  • 6
  • _"it always give error"_. That doesn't really tell us anything. Please specify exactly what errors you're getting. – Michael Oct 07 '13 at 07:35

2 Answers2

0

The errors you encounter are because different assemblers use different syntaxes. Your first program is in NASM format; the second one is in MASM format.

See wikipedia on asm syntax for several examples, and see MASM/NASM Differences and the link mentioned in there for tips.

Community
  • 1
  • 1
Jongware
  • 22,200
  • 8
  • 54
  • 100
0

Actually... I think the second one is Nasm syntax also (!!!). I think that "io.mac" is the work of the late Dr. Sivarama Dandamudi. The version I've got is for Linux (which wouldn't run on Windows 7), but this looks like an earlier version - probably for DOS (the "stack" declaration is the tipoff - these days the OS tells us where the stack is, we don't tell it). Does Windows 7 run DOS? If your first example runs, it does. If not, look into an emulator called "DosBox".

Exactly what happens when you try to assemble/link/run your second example, user2852570? We may be able to get you going with a little more information... provided you've got Dr. Dandamudi's "io.mac" and "io.o"...

Frank Kotler
  • 3,079
  • 2
  • 14
  • 9