I have traveled far and wide to seek your wisdom. I'm currently writing a program in assembly that involves some bit manipulation. Basically what I need to do figure out is how to store binary data into a char (8 bits). For example, how would I store 0000 0001 into a char variable?
Thank you kind /prog/
Name:
Anonymous2009-02-08 20:23
Also please keep in mind that I'm trying to take a low-level approach. I am not allowed to use high-level languages like C/C++ to implement a loop that allows me to convert binary numbers into an ASCII value, which is what I wanted to do but cannot.
I am not allowed to use high-level languages like C/C++
Do your own homework.
Name:
Anonymous2009-02-08 20:38
data:
db "00001111", 0
_main:
xor edx, edx
mov ebx, data
xor eax, eax
mov al, [ebx]
.loop:
cmp al, '0'
je .over
or edx, 1
.over:
shl edx, 1
inc ebx
mov al, [ebx]
or al, al
jnz .loop
Name:
Anonymous2009-02-08 20:46
>>3
i'm not asking you to do my homework. i just need help with some logic here
>>4
thanks for the code, but what i really need is an explanation of how i can manipulate bits in an existing data type (in this case a char). besides the architecture i'm writing for is SPARC rather than x86
Name:
Anonymous2009-02-08 20:55
Assembly doesn't have data types like char, it's all just bits, bytes, words, nibbles, etc...
To convert a binary number to ASCII, first convert to BCD, then OR each digit with 30h.
Name:
Anonymous2009-02-08 20:57
char acc = 0;
char *str = data;
while (i = *(str++)) acc = ((i&1) | (acc << 1);
Or whatever, I prefer ASM.
Name:
Anonymous2009-02-08 21:03
look up the hex value of your char in the ANSI table, find the char that matches your binary number... does SPARC asm even support char datatype?
Okay.. I think I understand what I need to do know. It took me a while to grasp the concept that assembly has no set data types as >>6 was explaining. Thanks /prog/
1: You didn't say you were using assembly.
2: That it doesn't have data types is the first fucking thing you learn when you open the book.
3: Get the fuck out, I feel bad for helping you.