The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
assembler level question
Discuss assembler level question in the C Programming forum on Dev Shed. assembler level question C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 7th, 2003, 07:21 PM
|
 |
not a fan of fascism (n00b)
|
|
Join Date: Feb 2003
Location: ct
|
|
|
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;
};
|

February 8th, 2003, 11:23 AM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
|
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!
|

February 8th, 2003, 01:40 PM
|
 |
not a fan of fascism (n00b)
|
|
Join Date: Feb 2003
Location: ct
|
|
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! 
|

February 8th, 2003, 01:44 PM
|
|
Contributing User
|
|
Join Date: Oct 2000
Location: Back in the real world.
|
|
you need to add 0x30 = 48. 
|

February 8th, 2003, 01:53 PM
|
 |
not a fan of fascism (n00b)
|
|
Join Date: Feb 2003
Location: ct
|
|
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. 
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|