Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Binary into char

Name: Anonymous 2009-02-08 20:18

/prog/,

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: Anonymous 2009-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.

Name: Anonymous 2009-02-08 20:31

I am not allowed to use high-level languages like C/C++

Do your own homework.

Name: Anonymous 2009-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: Anonymous 2009-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: Anonymous 2009-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: Anonymous 2009-02-08 20:57

char acc = 0;
char *str = data;

while (i = *(str++)) acc = ((i&1) | (acc << 1);


Or whatever, I prefer ASM.

Name: Anonymous 2009-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?

Name: Anonymous 2009-02-08 21:03

_main:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $24, %esp
        movb    $1, -9(%ebp)
        leave
        ret

Name: Anonymous 2009-02-08 21:30

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/

Name: Anonymous 2009-02-08 21:43

>>10
You can't be serious.

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.

Name: Anonymous 2009-02-08 21:53

>>11
YHBT

Name: Anonymous 2009-02-08 22:32

>>11
1. Actually, he did, read >>1 again.

Name: Anonymous 2009-02-08 22:45

>>13
YHBT

Name: Anonymous 2009-02-08 22:54

>>14
YHBMT

Name: Anonymous 2009-02-08 22:54

>>1-999
SPAWHBTC

Name: Anonymous 2009-02-09 7:56

YUO NEED TO READ ABOUT BITWISE OPERATIONS SUCH AS OR AND AND

Name: Anonymous 2009-08-16 22:36

Lain.

Name: Anonymous 2010-11-15 10:18

Name: Anonymous 2010-11-15 11:47

Name: Anonymous 2010-12-09 9:09

Name: Anonymous 2010-12-25 10:02

Name: Anonymous 2011-02-04 11:46


Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List