Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am new to assembly and I have to write this program.
The title says:
Write a program in assembly 8086 language that ask the user to input a number. If the character read is '0' it executes a + 3, otherwise if it is '1' it executes a-3 otherwise (if different from '0' and '1') it prints the character 'E' on the screen. The variable 'a' is 16 bits long and initialized at 15h 


What I have tried:

.model small 

.stack 100h

.data 
num db ?
num1 db 15h
msg1 db "Inserisci un numero... $"
msg2 db "24 $"
msg3 db "18 $"
msg4 db "Premere un tasto per uscire... $"

.CODE
	mov ax, @data 
	mov ds,ax 
	
	lea dx, msg1
	mov ah, 09h      ;output
	int 21h
	
	mov ah, 01h      ;input
	int 21h
	and al, 0Fh     
	mov num, al     
	
	call newLine
	
	CMP num, 00
	je numUguale1
	
	mov ah, 09h
	
	lea dx, msg2
	mov ah, 09h     
	int 21h
	
	mov ah, 01h    
	int 21h
	
	call newLine
	
	jmp fine
	
numUguale1:
	lea dx, msg3
	mov ah, 09h     
	int 21h
	
	mov ah, 01h
	int 21h        
	
	mov ax, 4c00h  
	int 21h
	
	call newLine
	
fine:
    lea dx, msg4	
	mov ah, 09h     
    int 21h
	
	mov ah, 01h
    int 21h        
	
	mov ax, 4c00h  
	int 21h
	
	call newLine
	
newLine:
	mov ah, 02h
	mov dl, 0Ah
	int 21h
	
	mov ah, 02h
	mov dl, 0Dh
	int 21h
	
	ret
END
Posted
Comments
Richard MacCutchan 29-Mar-21 3:49am    
What is the question?
Alessandro Dima 29-Mar-21 3:51am    
How can I write the part of code that outputs the letter E if the given number is not 0 or 1?
Richard MacCutchan 29-Mar-21 4:14am    
It is simple logic:
If the number is 0
print a value
Else If the number is 1
print another value
Else
print 'E'
Alessandro Dima 29-Mar-21 4:16am    
I know the logic, I just don't know how to write it in Assembly 8086 since I'm a couple days old on it. Maybe with multiple jumps? Or how? I don't know how to translate the logic into code in this case.
Richard MacCutchan 29-Mar-21 6:28am    
cmp al,0
je to_zero
cmp al,1
je to_one
; if you reach this point then it is not 0 or 1
; so print "E"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900