NASM variables have wrong value - nasm

main:
mov AH, 00h; set config to video
mov AL, 13h; choose the video mode
int 10h ; execute the configuration
mov AH,0Bh
mov BX,01h
int 10h
mov AH,0Ch; set the config for writing a pixel
mov AL,0Fh; choose color of pixel
mov BH,00h; set the page number
mov CX,BALL_X; set the column
mov DX,BALL_Y; set the line
int 10h
section .data
BALL_X DW 0Ah; X position(column)
BALL_Y DW 0Ah; Y position (row) of the ball
I am trying to display a pixel at coordinates saved in BALL_X, BALL_Y variables, but when I use this syntax, the position of the pixel differs, from when I hardcode the line,and column values.
variables:
hardcoded:

Related

Intel 8086 assembly reversing order of string

So I'm programming code in Intel 8086 assembly where I want to input two strings(one string in one line) and a want to save them to the variables. Each string can contain up to 100 utf8 characters. In the output, I try to change the order of then (the first line is going to be the second string from the input) but I get an error that the service 21h is trying to read from an undefined byte. Can you explain to me what I Should change in my code?
cpu 8086
segment code
..start mov ax, data
mov ds, ax
mov bx,stack
mov ss,bx
mov sp,dno
input1 mov ah,0x0a
mov dx, load
int 21h
mov bl,[load+1]
mov [chars1+bx],byte '$'
input2 mov ah,0x0a
mov dx, load
int 21h
mov bl,[load+1]
mov [chars2+bx],byte '$'
output mov dx,chars2
mov ah,9
int 21h
mov dx,chars1
mov ah,9
int 21h
end hlt
segment data
load db 200, ?
chars1 db ?
resb 100
chars2 db ?
resb 100
segment stack
resb 100
dno: db ?
but I get an error that the service 21h is trying to read from an undefined byte. Can you explain to me what I Should change in my code?
You are not loading the address of the input structure that is required by the DOS.BufferedInput function 0Ah. Read all about it in How buffered input works.
Emu8086 follows MASM programming style where mov dx, load will set the DX register equal to the word stored at the address load. To actually receive the address itself, you'll need to write mov dx, offset load.
A further problem is that both input1 and input2 try to use the same load input structure but with different buffer memories. The buffer has to be part of the input structure for this DOS function; it always has to reside at offset 2 from the provided address (load in your case).
This is how you can solve it:
...
input1: mov ah, 0Ah
mov dx, OFFSET loadA
int 21h
mov bl, [loadA+1]
mov bh, 0
mov [charsA+bx], byte '$'
input2: mov ah, 0Ah
mov dx, OFFSET loadB
int 21h
mov bl, [loadB+1]
mov bh, 0
mov [charsB+bx], byte '$'
output: mov dx, OFFSET charsB
mov ah, 09h
int 21h
mov dx, OFFSET crlf
mov ah, 09h
int 21h
mov dx, OFFSET charsA
mov ah, 09h
int 21h
...
loadA db 101, 0
charsA db 101 dup (0)
loadB db 101, 0
charsB db 101 dup (0)
crlf db 13, 10, "$"
...
101 provides room for 100 characters and 1 terminating carriage return.
Don't trust too much registers that you didn't set yourself! Write an explicite mov bh, 0 before using the whole of BX.
Since you want these strings outputted on different lines, I've added code to move to the start of the following line. See the crlf.

Is there a method to CMP two strings using emu8086?

I am working on a project to organize students mark in 3 exam using assembly language.
I want the emu to CMP the user's string by the ones in the text file, so if ZF set to 1, the emu will print the hole student's information (ID, Full Name, exams marks), that came from the compassion.
Here is the code, I take help from you guys.
ORG 100H
MOV DX, OFFSET MSG1
MOV AH, 9H
INT 21H
MOV DX, OFFSET MSG2
MOV AH, 9H
INT 21H
MOV DX, OFFSET LNBF ; GET STRING FROM USER
MOV AH, 0AH
INT 21H
MOV AL, 0 ; OPEN MY FILE
MOV DX, OFFSET FILE
MOV AH, 3DH
INT 21H
; READ FROM FILE
MOV BX, AX ; MOV HANDLER TO BX
MOV CX, 1 ; READ CHAR ONE BY ONE
LEA DX, DATABF
INT 21H
RET
FILE DB "MY.txt",0
LNBF DB 1EH,?
MSG1 DB "FIND A STUDENT BY HIS/HER LAST NAME:$"
MSG2 DB 0DH,0AH,0DH,0AH,"ENTER THE STUDENT'S LAST NAME->: $"
DATABF DW 0FFFH
Do correct these errors before you continue:
LNBF DB 1EH,? does a bad job setting up a buffer to input the student's name!
It overwrites MSG1 instead of providing a decent dedicated buffer.
The correct way is : LNBF DB 30, 0, 30 dup (0)
For detailed info about the DOS.BufferedInput function 0Ah see
How buffered input works
Your READ FROM FILE code forgets to specify the required function number 3Fh.
Use mov ah, 3Fh. Also you should not neglect the possibility that an error is returned via the carry flag!
Below is an example that you can use. It compares the carriage return-terminated name in the inputbuffer with the zero-terminated name in the text file. (The file could of course be using any string terminator that suits you...)
mov si, offset LNBF + 2 ; -> SI is address of student's name.
More:
call ReadOneCharFromFile ; -> AL
cmp al, 0
je SkipToNextNameInFile
cmp al, [si]
jne SkipToNextNameInFile
inc si
cmp byte [si], 13
jne More
call ReadOneCharFromFile ; -> AL
cmp al, 0
jne SkipToNextNameInFile
MatchFound:
...
SkipToNextNameInFile:
...

Why the program doesn't display the result?

I want to write a program which converts angles to radians.
format ELF executable 3
entry start
segment readable executable
deg2rad:
mov ax, [val]
mov bx, 180 ; rad = deg*pi/180
mul [pi] ;rad = deg*pi/180
div ebx
start:
mov [rad], ax ; get rad from ax
add [rad],'0' ; to string
mov ax,4 ; output
mov bx,1 ; output
mov cx,[rad] ; output
mov dx,10 ; output
int 0x80 ; output
exit:
mov eax,1
xor ebx,ebx
int 0x80
segment readable writeable
step dw 5
val dw 0.5
pi dw 3.14
rad dw ?
But after compiling and starting program I doesn't display the result. Why?
I think error in output. How fix?

8086 Write a program that takes one string from the input and inserts white space between every two letters

8086 Write a program that takes one string from the input and inserts white space between every two letters
using nasm and MSDOS
i have do following code but it is not working
start:
mov ax,data
mov ds, ax
mov es, ax
mov cx, size;cx will contain size,we need it to
; check if we have got 10 inputs from key board
lea dx, Enter_string;it will display a text on screen to enter text
mov ah, 9
int 21h
call get_string;input string from keyboard
mov ax, 4ch;terminating
int 21h
get_string:
mov si, 0; si will be used as index
mov bx, offset string
get_char:
mov ah, 1; get a char from keyboard
int 21h
mov [bx][si], al; saving input in string
inc si
cmp si,cx;if si=7 than, no need to take more input
jne get_char
ret
. You should prefer the simplicity of .COM programs while learning. They already start with all the segment registers pointing to the program.
. The DOS exit function expects the function number in AH.
. On NASM you don't use mov bx, offset string. Just write mov bx, string.
. It's easy to combine the tasks of inputting a string and interjecting space characters. See below code:
org 256 ;.COM programs have CS=DS=ES=SS
start:
mov cx, size ;cx will contain size,we need it to
; check if we have got 10 inputs from key board
mov dx, Enter_string ;it will display a text on screen to enter text
mov ah, 9
int 21h
call get_string ;input string from keyboard
mov ax, 4C00h ;terminating
int 21h
get_string:
push cx
mov si, 0 ; si will be used as index
get_char:
mov ah, 1 ; get a char from keyboard
int 21h
mov ah, " "
mov [string+si], ax ; saving input in string PLUS THE SPACE CHARACTER
add si, 2
dec cx ;if si=7 than, no need to take more input
jnz get_char
pop cx
ret
Remember that you don't actually need the last space character. Just overwrite it with the string terminator that you normally would add to this string!

Assembly - Writing Text In A Certain Location To Display On DOSBox

I am currently working on a game called: "4 In A Row". I am trying to write the instructions of the game to appear on DOSBox when I load the game up. I want to display it in a certain location on the screen but I don't know how to do that.
http://i.imgur.com/EjulgBV.png
I have outlined the code for the instructions.
Thank you very much for anyone who can help me.
The code:
inst1 db 'To drop a disc into one of the columns press: 1, 2, 3 or 4.',13,10,'$'
Instructions1:
lea dx, [inst1]
mov dx, offset inst1
mov ah, 9
int 21h
Try a "gotoxy" before displaying the text :
inst1 db 'To drop a disc into one of the columns press: 1, 2, 3 or 4.',13,10,'$'
;SET CURSOR POSITION (GOTOXY).
MOV DL, 20 ;SCREEN COLUMN.
MOV DH, 5 ;SCREEN ROW.
MOV AH, 2 ;SERVICE TO SET CURSOR POSITION.
MOV BH, 0 ;PAGE NUMBER.
INT 10H ;BIOS SCREEN SERVICES.
Instructions1:
lea dx, [inst1]
mov dx, offset inst1
mov ah, 9
int 21h
I should be cautious about answering on StackOverflow when I cannot check my work. But from memory...
I believe that you want to look into Int 10h using AH = 2. In English, you want to set the cursor position first, before calling 21h to write to STDOUT at that position.
I hope this gets you started down the right path!

Resources