Created
July 18, 2012 09:48
-
-
Save douglas-vaz/3135317 to your computer and use it in GitHub Desktop.
MASM Sum Average
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include io.h | |
data segment | |
lf db 0dh,0 | |
cr db 0ah,0 | |
n_prompt db "Enter n:",0 | |
num_prompt db "Enter number",0 | |
res_sum db "Sum = ",0 | |
res_avg db "Average = ",0 | |
n dw 40 DUP(?) | |
bar dw 40 DUP(?) | |
arr dw 100 DUP(?) | |
data ends | |
code segment | |
Assume cs:code, ds:data | |
start: mov ax, data | |
mov ds,ax | |
output n_prompt | |
output lf | |
output cr | |
inputs bar,40 | |
atoi bar | |
mov n,ax | |
lea bx, arr | |
mov dx,n | |
__inp: output num_prompt | |
output lf | |
output cr | |
inputs bar, 40 | |
atoi bar | |
mov [bx],ax | |
add bx,2 | |
dec dx | |
cmp dx,0 | |
jne __inp | |
mov ax,0 | |
lea bx,arr | |
mov dx,n | |
sum: add ax,[bx] | |
add bx,2 | |
dec dx | |
cmp dx,0 | |
jne sum | |
itoa bar,ax | |
output res_sum | |
output bar | |
avg: cwd | |
idiv n | |
itoa bar, ax | |
output cr | |
output lf | |
output res_avg | |
output bar | |
quit: mov al,0 | |
mov ah,4ch | |
int 21h | |
code ends | |
end start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Enter n:
3
Enter number
2
Enter number
3
Enter number
4
Sum = 9
Average = 3