1 Write
a assembly language program to create an array of 10 numbers, get it populated via keyboard, and
print all those numbers which are duplicated within the array.
org 100h
INCLUDE 'EMU8086.INC' ;include an assembly library
.MODEL SMALL
.STACK 100h
.DATA
ARR DB 10 DUP(?) ; declare array with null value initially
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
XOR BX,BX
XOR CX,CX
PRINT "How many number you want to store(1-9): "
MOV AH,1
INT 21H
AND AL,0FH ;convert from ascii value to real value
MOV CL,AL
MOV BL,AL
MOV SI,0
PRINTN
PRINT "Enter values(without press enter or space): "
PRINTN
INPUT:
INT 21H
MOV ARR[SI],AL
INC SI
LOOP INPUT
PRINTN
PRINT "OUTPUT: "
PRINT
MOV CX,BX
MOV SI,0
MOV AH,2
OUTPUT:
MOV DL,ARR[SI]
INT 21h
INC SI
LOOP OUTPUT
MAIN ENDP
END MAIN
ret
ret
2 Write a program to create a procedure sum that takes two numbers as arguments,
does their summation and returns the result. Call this procedure twice in your
main program. Make sure to pass arguments via registers
org 100h
section .text
global _start ;must be declared for using gcc
_start: ;tell linker entry point
mov ecx,'4'
sub ecx, '0'
mov edx, '5'
sub edx, '0'
call sum ;call sum procedure
mov [res], eax
mov ecx, msg
mov edx, len
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov ecx, res
mov edx, 1
mov ebx, 1 ;file descriptor (stdout)
mov eax, 4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
sum:
mov eax, ecx
add eax, edx
add eax, '0'
ret
section .data
msg db "The sum is:", 0xA,0xD
len equ $- msg
segment .bss
res resb 1
ret
3.
Write a program to get a string from a keyboard restricting key presses
pertaining to vowels and print it back on screen
; You may customize this and other start-up templates;
; The location of this template is c:\emu8086\inc\0_com_template.txt
org 100h
.model small
.data
var db 0 ;variable for input
arr db 10 (?) ;array of 10 bytes for 10 vowels
msg db "Enter 10 vowels or enter dollar to terminate",10,13,"$"
msg1 db 10,13,"Enter a vowel only",10,13,"$"
msg2 db 10,13,"Array contents are",10,13,"$"
.code
main proc
mov ax,@data
mov ds,ax
mov ah,9 ;code service for display msg to enter content
lea dx,msg
int 21h
mov cx,10 ;to take 10 vowels and work as a counter variable
input: ;label to work as a loop statement
mov ah,1 ;code service for a byte input
int 21h
mov var,al ;store input
mov ah,2 ;next line code service
mov dl,10
int 21h
mov ah,2 ;carriage return code service
mov dl,13
int 21h
cmp var,'A' ;compare variable with vowels
jz store ;if equal then ZF is set and jump to 'store' label
cmp var,'a'
jz store
cmp var,'E'
jz store
cmp var,'e'
jz store
cmp var,'I'
jz store
cmp var,'i'
jz store
cmp var,'O'
jz store
cmp var,'o'
jz store
cmp var,'U'
jz store
cmp var,'u'
jz store
cmp var,'$' ;if $ is entered then goto finish
jz finish
mov ah,9 ;if above cases didn't match and no jmp was made
lea dx,msg1 ;then it wasn't vowel or $(invalid input)
int 21h
backToLoop: ;check if 10 vowels were entered and stored
cmp cx,0
ja input ;if dx!=0 then loop
jmp finish ;else finish no more input is permitted
store:mov al,var ;store the vowel
mov arr[di],al ;di is initially zero
inc di
dec cx ;update dx that one vowel was read and stored
jmp backToLoop ;go to check if dx==0(i.e,10 vowels were given>
finish: ;to display contents 'di' elements
mov cx,di
mov ah,2 ;code service for printing nextline
mov dl,10
int 21h
mov ah,9
lea dx,msg2
int 21h
mov ah,2
mov dl,10 ;code service for printing nextline
int 21h
for1:
mov ah,2
mov dl,arr[si] ;display a character element
int 21h
inc si
mov ah,2
mov dl,' ' ;display a character space
int 21h
loop for1
mov ah,4ch ;code service for returning control to OS
int 21h
main endp
end
;output
;code
ret
4. Write a program to get a multi-digit
number from the keyboard and store the number in memory in its binary form.
Please don't make use of stack
org 100h
.MODEL SMALL
.STACK 100H
.DATA
MSG DB "ENTER A NUMBER: $"
TOTAL DB 0
VALUE DB 0
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX
MOV AH, 9
LEA DX, MSG
INT 21H
READ:
MOV AH, 1
INT 21H
CMP AL, 13
JE ENDOFNUMBER
MOV VALUE, AL
SUB VALUE, 48
MOV AL, TOTAL
MOV BL, 10
MUL BL
ADD AL, VALUE
MOV TOTAL, AL
JMP READ
ENDOFNUMBER:
MAIN ENDP
ret
answer and question of 8086 languege
woow
ReplyDelete