|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
||||
|
||||
|
assembler level question
I am trying to convert a hex number into a binary one, and im having some trouble. for output, i am getting odd symbols, like smiley faces or triangles etc.. here's my code, any help greatly appreciated:
//Ex03s07_BinOut32 #include <iostream.h> #include <conio.h> // for putch() void HexOut32(int m) { // outputs m binary. char c; // tmp variable __asm { mov eax, m push ebx ; save reg so can use push ecx mov ch, 32 ; 32 binary digits to display HexOut32_1: mov CL, 1 rol eax, CL mov BL, AL ; determine binary code for digit and BL, 00000001b ; mask add BL, 00011110b HexOut32_2: mov c, BL push eax ; save value push ecx ; save count } _putch (c); __asm { pop ecx ; restore counts pop eax ; restore value dec ch jnz HexOut32_1 pop ecx pop ebx } return; } int main() { int n; do { cout << "\n\nEnter number (in hex, 0 to exit): "; cin >> hex >> n; if (n == 0) break; cout << "Here it is: "; cout.flush(); HexOut32(n); } while (1); return 0; }; |
|
#2
|
||||
|
||||
|
Try changing this part:
; determine binary code for digit and BL, 00000001b ; mask add BL, 00011110b to this: ; determine binary code for digit and BL, 00000001b ; mask add BL, 00110000b Hope this helps! |
|
#3
|
||||
|
||||
|
U ROCK MAN!!! THANKS!! tried it and it works, but one question:
i'm one of those types who has to know why everything works... why?? i thought i had to add 30 to what i had?? thanks much! ![]() |
|
#4
|
|||
|
|||
|
you need to add 0x30 = 48.
![]()
__________________
-- Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more. |
|
#5
|
||||
|
||||
|
oh god i just figured out what it was, i was looking at the ascii set with hex indices!! LOL, in hex 0 = 30 and 1 = 31!! thanks a lot for your help guys!! much faster than my jerk teacher who hasnt replied to my email in 2 days.
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > assembler level question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|