Numbers divisible by their individual digits, but not by the product of their digits.: Difference between revisions

Add 8086 assembly
(Add MAD)
(Add 8086 assembly)
Line 5:
<br>where &nbsp; <big>'''n &nbsp; &lt; &nbsp; 1000''' </big>
<br><br>
 
=={{header|8086 Assembly}}==
<lang asm> cpu 8086
org 100h
section .text
mov si,1 ; Current number
number: mov bp,1 ; BP holds product
mov di,si ; DI holds number
digit: mov ax,di ; Get digit
xor dx,dx
mov cx,10
div cx
mov di,ax ; Store remaining digits in DI
test dx,dx ; Is the digit zero?
jz next ; Then this number is not valid
mov cx,dx ; Is the number divisible by the digit?
xor dx,dx
mov ax,si
div cx
test dx,dx
jnz next ; If not, this number is not valid
mov ax,bp ; Otherwise, multiply digit into product
mul cx
mov bp,ax
test di,di ; More digits?
jnz digit ; If so, do next digit
mov ax,si ; Is the number divisible by the product?
xor dx,dx
div bp
test dx,dx
jz next ; If so, this number is not valid
mov ax,si ; Otherwise, print the number
call prnum
next: inc si ; Next number
cmp si,1000 ; Are we there yet?
jne number ; If not, do the next number
ret ; But if so, stop
;;; Print number in AX
prnum: mov bx,dbuf ; Start of buffer
mov cx,10 ; Divisor
.dgt: xor dx,dx ; Divide by 10
div cx
add dl,'0' ; Make ASCII digit
dec bx
mov [bx],dl ; Store digit
test ax,ax ; Any more digits remaining?
jnz .dgt ; If so, next digits
mov dx,bx ; Print string using MS-DOS
mov ah,9
int 21h
ret
section .data
db '*****'
dbuf: db 13,10,'$'</lang>
 
{{out}}
 
<pre style="height: 50ex;">22
33
44
48
55
66
77
88
99
122
124
126
155
162
168
184
222
244
248
264
288
324
333
336
366
396
412
424
444
448
488
515
555
636
648
666
728
777
784
824
848
864
888
936
999</pre>
 
=={{header|Ada}}==
2,094

edits