Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Codes should be properly commented. Remember Google is your best friend and Book

ID: 3780158 • Letter: C

Question

Codes should be properly commented. Remember Google is your best friend and Book is the best resource. Your task is to write assembly code to initialize an array of 10 numbers. Then calculate mean, minimum and maximum of those numbers. Based on the calculated mean, you will have to implement an up or down counter. For example, if 'mean' is close to 'minimum', implemented counter will count downwards and if mean is close to the 'maximum' of the array of numbers implemented counter will count upwards. The initial value of the counter should be same as the calculated 'mean' of the array. The counter should count to either maximum or minimum of the array (depending on if it's an up or down counter) then reset to the 'mean' and repeat. The counter values (while it is counting) should he displayed on the Seven Segment Display units and the 8-bit bar LED unit available on the Dragon EVB. There should be a constant delay of 1.5 seconds between each update of counter value.

Explanation / Answer

Solution :

Assembly level code for finding average, minimm and maximum of ten numbers :

data segment
sum dw 2dup(0)
msg1 db 'Enter 10 numbers:', 0dh,0ah,'$' The value to be entered.
msg2 db 'Mean'= ','$'
ends

stack segment
dw 10dup(0)
ends

code segment
assume cs:code,ds:data,ss:stack
main proc far

mov ax, data
mov ds, ax

mov ax, stack
mov ss, ax

mov ah, 09h
mov dx, offset msg1
int 21h

mov ch, 10

NextNumber:
mov cl, 4
mov di, 0

get:
mov ah, 07h
int 21h

cmp al, 30h
jb get
cmp al, 39h
ja get

mov ah, 02h
mov dl, al
int 21h

sub al, 30h

mov bl, al
mov ax, 10
mul di

mov bh, 0
add ax, bx

mov di, ax   

dec cl

jnz get

add sum, di
mov sum+2, 0
adc sum+2, 0

mov ah, 02h
mov dl, 0ah
int 21h
mov dl, 0dh
int 21h

dec ch

jnz NextNumber

mov dx, sum+2
mov ax, sum
mov bx, 10
div bx

mov ah, 09h
mov dx, offset msg2
int 21h

mov cx, 4
mov bx, 10

next1: mov dx, 0
div bx

push dx

dec cx
jnz next1

mov cx,4

next2: pop dx
add dl, 30h
mov ah, 02h
int 21h

dec cx
jnz next2

mov ah, 4ch
int 21h
MOV AX,DATA
MOV DS,AX

LEA SI,ARR
MOV AL,ARR[SI]
MOV MIN,AL
MOV MAX,AL

MOV CX,LEN
REPEAT:
MOV AL,ARR[SI]
CMP MIN,AL
JL CHECKMAX

MOV MIN,AL //checks for the minimum of the number
CHECKMAX:
CMP MAX,AL
JG DONE

MOV MAX,AL //checks for the maximum of the number
DONE:
INC SI
LOOP REPEAT

MOV AH,4CH
INT 21H

main endp

ends

end main