2

I'm learning assembly language with Intel syntax. I was using Win XP and MASM 4.0 and everything was ok. Recently I migrated all of my homeworks to Linux (Ubuntu 10.04), trying to assemble codes with nasm or nasm I receive a lot of errors (almost in each line). I also added .intel_syntax in first line. here is my first assembly program:

.intel_syntax
stksg   segment stack
    db 32 dup ("stack")
stksg   ends

datasg segment para 'data'
    m1 db "Enter 1st number: " , '$'
    m2 db "Enter 2nd number: " , '$'
    number1 label byte
    max1 db 10
    ln1 db ?
    n1  db 10 dup(0)
    dollar db '$'
    number2 label byte
    max2 db 10
    ln2  db ?
    n2 db 10 dup(0)
    p1 db 10 dup(' ')
datasg ends

codesg segment para 'code'
    main proc far
    assume ds:datasg, cs:codesg, ss:stksg
    mov ax, datasg
    mov ds, ax
    mov ah,06h  ;clear screen
    mov al,25   ;number of rows to clear
    mov ch,0    ;UL row
    mov cl,0    ;UL col
    mov ch,24   ;BR row
    mov cl,79   ;BR col

    mov bh,07h  ;attribute (back:black, text:white)
    int 10H
    mov dx, offset m1   ;prints m1
    mov ah,9h
    int 21h
    mov ah,0ah      ;gets number 1
    mov dx,offset number1
    int 21h 
    mov ah,02h      ;move cursor
    mov dh,1
    mov dl,0
    mov bh,0
    int 10h
    mov dx, offset m2   ;prints m2
    mov ah,9h
    int 21h  
    mov ah,0ah      ;gets number 2
    lea dx,number2
    int 21h 
    mov ah,09h
    mov bl,ln1
    lea ax,ln1
    ;mov [ln1+1],'$'
    mov p1,bl
    add ln1,30h
    ;lea dl,(offset p1)+1
    ;mov [dl],'$'
    ;mov offset p1+1,'$'
    lea dx,ln1
    int 21h   
;   mov bx,0
;   mov cx,1
;f1:    mov dl,[offset n1+cx]
;   sub dl,30h      ;convert to number   
;   mov al,10   
;   mul bx          ; ax = bx*10    
;   mov bx,ax       ; bx=ax === bx=bx*10    
;   add bx,dl    
;   inc cx   
;   cmp cx,ln1    
;   jne f1
    mov ah,01h    
    int 21h
    mov ax, 4c00h
    int 21h
    main endp
codesg ends
end main
end
sorush-r
  • 10,490
  • 17
  • 89
  • 173

2 Answers2

0

Have you read the Error messages that GCC gives you? There's a lot of "no such instruction" error.

Error: no such instruction: `stksg segment stack

You can read about the Intel Instruction Set for x86 and see what Instructions you can use.

So what you need to do is Go over the Intel Instruction set and see to it that you use the appropriet instructions.

For instance when you want to create a procedure you write:

procedureName: and the code for that procedure after the colon. The datasegment and text segment are both defined like this .data and .text. Here is an example of a properly written procedure taken from a IO system I wrote.

setinpos:                                                               
        pushl %ebp
        movl %esp, %ebp

        movl 8(%ebp), %eax

        movl %eax, BUFFERT_POSITION_POINTER

        movl %ebp, %esp
        popl %ebp

        ret

Start with converting Small portions of the code, line by line.

Filip Ekberg
  • 36,033
  • 20
  • 126
  • 183
  • Did I missunderstand the question/the problem? When I read your quesiton again, I get the feeling you want to use MASM syntax with NASM? – Filip Ekberg Nov 07 '10 at 09:46
  • 1
    Yes. I really need to use MASM syntax in Ubuntu with NASM, GAS or any other thing. now I'm trying to run my old MASM by wine in Ubuntu... : – sorush-r Nov 07 '10 at 15:38
  • afaik using MASM on anything other than Windows violates Microsofts copyrights. Maybe you should check this project out: http://www.japheth.de/JWasm.html and this http://stackoverflow.com/questions/304555/masm-under-linux – Filip Ekberg Nov 07 '10 at 15:45
  • *"Have you read the Error messages that GCC gives you? "* - Did you read the question? He wants to use `.intel_sytax`, and he wants to know how to specify it in NASM. I'm here for the same reason. – jww Nov 10 '15 at 11:34
  • @jww, Rather a long time ago I answered this, did you see my comment on the copyright issue? – Filip Ekberg Jan 07 '16 at 04:42
0

Nasm is an Intel-syntax assembler. MASM and NASM have some diffence which are mentioned in NASM manual. Beside, you can't use DOS interrupts in Linux. Linux system call is via intterupt 80h.

Linh Dao
  • 1,305
  • 1
  • 19
  • 31