So I'm just toying around with binary so I have a few new tricks to teach when school starts again next year ( gotta hate physics classes! ) but anyway I got this working which prints out a decimal number's binary in reverse ( the quotients ) ; So now I got a program that turns 10 into 0101 ( 1010 would be correct ) ; How do I reverse these bits? Should I be storing them as a specific datatype? I wrote the same function in delphi ages ago and I handled the sequence as a string which made reversing it that much easier but then again I don't want to do that this time.
BITS 32
extern __cprintf
extern __getch
extern _ExitProcess
global main
section .data
CharFormat db "%",0
State_One db "1",0
State_Zero db "0",0
StateMsg db 0ah,"Quotient %i",0ah,"Remainder %i",0ah,0
IntFormat db 0ah,"Result : %i",0ah,0
DoneMsg db 0ah,"Done",0ah,0
ANumber dd 10
Answer dd 0
section .text
main:
mov EAX , 1500
mov dword [Answer] ,1500
;Save Initial Value
;DIV performs unsigned integer division. The explicit operand provided is the divisor; the dividend and destination operands are implicit, in the following way:
;For DIV r/m8, AX is divided by the given operand; the quotient is stored in AL and the remainder in AH.
;For DIV r/m16, DX:AX is divided by the given operand; the quotient is stored in AX and the remainder in DX.
;For DIV r/m32, EDX:EAX is divided by the given operand; the quotient is stored in EAX and the remainder in EDX.
aLoop:
mov EDX , 0
mov EAX , dword [Answer]
mov ECX , 2
DIV ECX
mov dword [Answer] , EAX
push EDX
push dword [Answer]
push StateMsg
CMP EAX,0
JE Done
call __cprintf
call __getch
JMP aLoop
Done:
push 1
push EAX
push StateMsg
call __cprintf
call __getch
Is there some sort of an array I can use? Suggestions?
Thanks! ( working with nasm on Win64 )