저는 emu8086에서 초보자입니다. 수정이 불가능한이 코드에 문제가 있습니다. 10 진수에서 2 진수로 변환해야 할 때가 있습니다. 예를 들어, 4,8,15,16,255와 같은 숫자를 사용하면 모든 것이 잘됩니다. 그러나 예를 들어 2,9,17,254를 사용하면 올바른 숫자가 표시되지 않습니다. 이 일에 정말로 도움이 필요해.배열을 사용하여 10 진수에서 2 진수로 변환
.model small
.data
exp db 8 dup (?)
num dw 09
var dw 2
.code
start:
mov ax,@data
mov ds,ax
mov di,0
mov ax,num ;I put my number in ax
Binary: ;Here I make the conversion from decimal to binary
div var
mov exp[di],dl
inc di
cmp al,0 ;If my number is equal to 0 it breaks the cicle and shows the array in the next function
ja Binary
dec di
mov cx,di
Show: ;Here I show the array backwards so we can see the real binary number
mov bl,exp[di]
add bl,30h
mov dl,bl
sub bl,30h
mov ah,2
int 21h
dec di
loop Show
int 21h
end start:
단부
2로 나누기 위해'div'를 사용하지 마십시오! 그것은 교대보다 약 30x 느리고 즉각적인 피연산자를 취할 수 없습니다. https://stackoverflow.com/questions/40354978/why-is-this-c-code-faster-than-my-hand-written-assembly-for-testing-the-collat/40355466#40355466 –
Peter. 고맙습니다. –