47 lines
890 B
Text
47 lines
890 B
Text
cpu 8086
|
|
org 100h
|
|
section .text
|
|
mov si,1 ; Square counter
|
|
mov di,si ; Current square
|
|
mov bp,si ; Cube counter
|
|
mov bx,si ; Current cube
|
|
xor cx,cx ; Counter
|
|
loop: cmp di,bx ; Square > cube?
|
|
jbe check
|
|
inc bp ; Calculate next cube
|
|
mov ax,bp
|
|
mul bp
|
|
mul bp
|
|
mov bx,ax
|
|
jmp loop
|
|
check: je next ; Square != cube?
|
|
inc cx ; Then count it
|
|
mov ax,di
|
|
call print ; Print it
|
|
next: inc si ; Next square
|
|
mov ax,si
|
|
mul si
|
|
mov di,ax
|
|
cmp cx,30 ; Done yet?
|
|
jb loop
|
|
ret
|
|
print: push bx ; Print AX - save registers
|
|
push cx
|
|
mov cx,10
|
|
mov bx,num ; End of number buffer
|
|
dgt: xor dx,dx ; Extract digit
|
|
div cx
|
|
add dl,'0'
|
|
dec bx ; Store digit
|
|
mov [bx],dl
|
|
test ax,ax ; More digits?
|
|
jnz dgt ; If so, go get them
|
|
mov dx,bx ; If not, print string
|
|
mov ah,9
|
|
int 21h
|
|
pop cx ; Restore registers
|
|
pop bx
|
|
ret
|
|
section .data
|
|
db '*****' ; Placeholder for number
|
|
num: db ' $'
|