I'm trying to compile this program using NASM:
.model small
.STACK 100h
.data
no dw 31429
nstr db 6 dup(' ')
idv dw 10
.code
.startup
mov ax, dgroup
mov ds, ax
mov si,5
mov nstr[si], '$'
dec si
mov ax, no
mov dx,0
loop1:
div idv
add dl, '0'
mov nstr[si],dl
dec si
mov dx,0
cmp ax,0
jne loop1
listn:
mov ah, 09h
mov dx, offset nstr
int 21h
stopprg:
mov ah, 4ch
int 21h
end
And here's the output:
Afis.asm:6: error: attempt to define a local label before any non-local labels
Afis.asm:6: error: parser: instruction expected
Afis.asm:7: error: attempt to define a local label before any non-local labels
Afis.asm:7: error: parser: instruction expected
Afis.asm:8: warning: label alone on a line without a colon might be in error
Afis.asm:8: error: attempt to define a local label before any non-local labels
Afis.asm:10: error: comma expected after operand 1
Afis.asm:12: warning: label alone on a line without a colon might be in error
Afis.asm:13: warning: label alone on a line without a colon might be in error
Afis.asm:20: error: comma, colon, decorator or end of line expected after operand
Afis.asm:37: error: comma, colon, decorator or end of line expected after operand
Afis.asm:49: error: comma, colon, decorator or end of line expected after operand
Afis.asm:55: warning: label alone on a line without a colon might be in error
From what I know the program works fine with DosBOX, as my colleague told me, unfortunately I'm using linux and I cannot understand why I'm getting those errors.
Can someone point out where I'm making errors and how I can fix this?
Related
I'm confused how to compile 8086 code in nasm.
i used following command to assemble:
nasm hello.asm -o hello.o //;(Something wrong with this?)
This is 8086 Hello world code:
USE16
.model small
.stack 100h
.data
msg db "Hello World !$"
.code
main proc near
mov ax,#data
mov ds,ax
mov dx, offset msg
mov ah, 09h
int 21h
mov ah,00
int 21h
endp
end main
And this is the output
nasm hello.asm -o hello.o
hello.asm:3: error: parser: instruction expected
hello.asm:4: error: parser: instruction expected
hello.asm:5: warning: label alone on a line without a colon might be in error [-w+label-orphan]
hello.asm:9: warning: label alone on a line without a colon might be in error [-w+label-orphan]
hello.asm:11: error: parser: instruction expected
hello.asm:16: error: comma, colon, decorator or end of line expected after operand
hello.asm:23: warning: label alone on a line without a colon might be in error [-w+label-orphan]
hello.asm:24: error: parser: instruction expected
I'm on Debian 9. These are the errors:
andrea#debian:~/Assembly/sandbox$ nasm -f elf -g -F stabs sandbox.asm
sandbox.asm:8: error: comma, colon, decorator or end of line expected after operand
sandbox.asm:9: error: comma, colon, decorator or end of line expected after operand
sandbox.asm:11: error: comma, colon, decorator or end of line expected after operand
sandbox.asm:12: error: comma, colon, decorator or end of line expected after operand
This is the code:
section .data
section .text
global _start
_start:
nop
mov eax 10
mov ebx 12
mov eax 1
mov ebx 0
int 80H
nop
section .bss
What's the problem causing these errors and how can I fix it?
If I use the following code where I fix the commas between operands I get a different error:
section .data
section .text
global_start
_start:
nop
mov eax,10
mov ebx,12
mov eax,1
mov ebx,0
int 80H
nop
section .bss
The error I get is:
sandbox.asm:4: warning: label alone on a line without a colon might be in error
Why do I get this error and how can I fix it?
I suppose there is a space missing and it should be:
global _start
in line 4.
I also suspected that the hexadecimal constant may be in incorrect format, because of missing 0 prefix, but it should be ok as long as the number starts with a digit, as Michael Petch mentioned in the comments (and according to the documentation of NASM available here: http://www.nasm.us/doc/nasmdoc3.html).
I write assembly code
section .data
mas dd 1, 2, 3, 4, 5
section .text
global start
start:
xor eax, eax
xor si, si
xor ecx, 20
sum:
push mas[si]
add ax, mas[si]
add esi, 4
cmp ecx, esi
jne sum
But when i compile i got error
test.asm:12: error: comma, colon, decorator or end of line expected after operand
test.asm:13: error: comma, colon, decorator or end of line expected after operand
What's a problem? NASM v 2.13
I'm having a problem printing a string which I read from the keyboard, if the string is the maximum length then it works but if I enter only 3 characters for example I got a blank black space, this is the code:
assume cs:code,ds:data
data segment
sir db 12 dup (?),'$'
mesaj db "Who`s your daddy?",13,10,"$"
data ends
code segment
start:
mov ax,data
mov ds,ax
mov dx,offset mesaj
mov ah,09h
int 21h
mov bx,offset sir
mov sir[0],11
mov dx,bx
mov ah,0ah
int 21h
mov dx,offset sir
mov ah,09h
int 21h
mov ah,01h
int 21h
mov ax,4c00h
int 21h
code ends
end start
If you change your sir db 12 dup (?), '$' to sir db 12 dup('$'),'$', and your mov dx, offset sir to mov dx, offset sir + 2 as someone else has suggested in comments, your code should work.
However, if you want to see the results clearly, you will need to print some newline characters.
This is because the 0ah routine (string input):
echoes your input to the terminal, including the carriage return (0dh) it picks up when you press Enter, but not the line feed (0ah) that would move the cursor to the next line
puts all your input including the carriage return in the specified memory location, but again no line feed.
This means that immediately after the input routine runs, your cursor is sitting at the beginning of the line you did your input on, which still contains your echoed input. So print a line feed character to make it go to the next line before you do anything else.
Next, when you print the string out, the carriage return at the end is picked up and the cursor is returned to the beginning of the line, but again there is no line feed. It is quite likely that whatever gets written afterwards (by your program, or any other program on the system) will overwrite what you have printed. So, again, print a line feed to make it go to the next line first.
Printing a line feed should be as simple as:
data segment
....
lf db 10, '$'
....
code segment
....
mov dx, offset lf
mov ah, 9
int 21h
....
mov dx, offset lf
mov ah, 9
int 21h
....
I'd like to write a program that counts the amount of specific symbols in string using scasb and masm32, I found the example, but I couldn't figure out why i'm getting errors.
Here's the part of code:
.data
str db '. . .'
len_str=$-str
.code
start:
mov ax,#data
mov ds,ax
mov es,ax
lea di,str
mov cx, len_str
mov al,' '
mov bx,0
cld
cycl:
repe scasb
jcxz exit
inc bx
jmp cycl
exit:
getting
A2008 syntax error db, str
A2006 syntax error len_str
A2148 invalid symbol type in expression: exit
A2004: symbol type conflict
str is an instruction, it is the mnemonic for Store Task Register. You cannot use it as a label name as you are trying to do. Name it something else and that should take care of your errors