Write a program in Assembly language that calculates the maximum and minimum of 10 numbers stored in memory and writes them to the memory locations.
#using loop
num: dw 56, 45, 36, 67, 76, 22, 89, 12, 29, 83
min: dw 0
max: dw 0
I wrote a codem but I got an error when I executed it
[ORG 0x0100]
jmp start
num: dw 56, 45, 36, 67, 76, 22, 89, 12, 29, 83
min: dw 0
max: dw 0
start: mov ax, [num]
mov bx, 0
mov cx, 10
move [max], ax
mov [min], ax
again:
mov ax, [num+bx]
add bx, 2
cmp ax, [max]
Jl next
mov [max], ax
next: mov [min], ax
loop again
end: mov ax, 0x4c00 ;terminate program
int 0x21
Program[ executed and verified in emu8086 simulator]
Note:- memory values are represented in hexa decimal format
DATA SEGMENT
num dw 56, 45, 36, 67, 76, 22, 89, 12, 29, 83
min dw ?
max dw ?
DATA ends
CODE SEGMENT
ASSUME cs:code, ds:data
start: mov ax, data
mov ds, ax
mov cx, 10
lea si,num
mov bx, [si]
up:
mov ax, [SI]
cmp ax, bx
jge nxt
mov bx, ax
nxt:
inc si
inc si
loop up
mov min,bx
mov cx, 10
lea si,num
mov bx, [si]
up1:
mov ax, [SI]
cmp ax, bx
jle nxt1
mov bx, ax
nxt1:
inc si
inc si
loop up1
mov max,bx
mov ah,4ch
int 21h
code ends
end start
Get Answers For Free
Most questions answered within 1 hours.