; PROGRAM: SUM OF SQAURES
read macro num
mov ah, 01h
int 21h
mov bh, al
int 21h
mov bl, al
sub bh, 30h
mov al, 0ah
mul bh
sub bl, 30h
add al, bl
mov num, al
endm
print macro s
mov ah, 09h
mov dx, offset s
int 21h
endm
data segment
cnt db ?
psum db 10 dup('$')
msg db 'Enter limit: $'
nl db 0ah, 0dh, '$'
sumis db 'Sum of cubes: $'
data ends
code segment
assume ds:data, cs:code
start:
mov ax, data
mov ds, ax
print msg
read cnt
mov cl, cnt
mov ch, 00h ;count
mov bx, 0000h ;sum
cmp cx, 0000h
je ZERO
SUMCUBE:
mov al, cl
mul al
mul cx
add bx, ax
loop SUMCUBE
ZERO:
mov ax, bx
mov si, offset psum
call hex2ascii
print nl
print sumis
print psum
mov ah, 4ch
int 21h
hex2ascii proc near
mov cx, 0000h
REPDIV:
mov dx, 0000h
mov bx, 000ah
div bx
add dl, 30h
push dx
inc cx
cmp ax, 000ah
JGE REPDIV
add al, 30h
mov [si], al
inc si
SAVEASCI:
pop dx
mov [si], dl
inc si
loop SAVEASCI
STOP1:
mov [si], '$'
ret
hex2ascii endp
code ends
end start
**************************
OUTPUT
Z:\S5IT\masm>sum_cubes
Enter limit: 04
Sum of cubes: 100
**************************
0 comments:
Post a Comment