# 8-bit user-defined binary addition (signed)

Hey guys. Let me first say that it looks like a nice forum you got here ;-) Very good. Well, here's my question:

I am using MASM 6.15 and I am very interested to understand how to accept two user defined 8-bit signed binary strings, ADD them together, then output to the screen the signed result in ASCII. When that is understood, I would also like to expand on the program to identify whether there was an underflow/overflow condition present. I searched around the forums and google'd this, but no luck... Any ideas?

Kris Hermansen

• Question: how to add user defined 8-bit signed binary strings,
then output to the screen the signed result in ASCII.

[green]
I don't really have the answer for you, but:
Signed basicly means that bit-7 is set or not.
So your program flow could check bit-7
TEST AL,10000000b
JNZ BIT-7isSET ; jump if bit is set
OR AL,AL
JS BIT-7isSET ; this works too
Many programs treat signed bytes/words differently (maybe?).
If bit-7 is set, it's a minus number (er vice/versa)
If bit-7 is set, it's less than 128 = clear bit-7 & use bits 0-6 ?
If bit-7 is set, it's greater than 127 = unsigned
So figgure out what your program is using them for and process them accordingly.
You can change signed to unsigned then ADD SUB DIV etc
Or if bit-7 = set subtract the minus number? (bits 0-6)
So bit-7 is actually a toggle indicator & bits 0-6 holds the value.
AND AL,01111111b ; keeps bits 0-6
I've seen the following used under certian conditions
AND AL,10000000b ; zero out bits 0-6
JZ ITsSIGNED ;then it jumps if it's signed (maybe it's JS?)
Check an Intel opt code doc for signed specfic instructions & work with your signed numbers according to your programs use & the instructions available.
Make small .com file, check small code snipits, use the good ones.
Make/get a Binary printer to show your output.
TOP:
SHL AL,1
JC PRINT_A_1 ; jump and print a 1, loop back to TOP CX=8 times
PRINT_A_0: ; print a 0 here, repeat loop thingie

I don't know what type of ASCII number you want printed?
HEX, DECIMAL, BINARY, OCTAL, ?
But I have some printer proc's made for Nasm in C:
asminc16 at
http://bitdog.home.att.net/file/nasmenv.zip
Do anything you want with my stuff in there.
Describing a converter/printer here would be huge, as would be includeing working code.
I hope that helps somehow.
And if any one has corrections or info to add, please feel free to post.
Bitdog
[/green]

• : Question: how to add user defined 8-bit signed binary strings,
: then output to the screen the signed result in ASCII.
:
: [green]
: I don't really have the answer for you, but:
: Signed basicly means that bit-7 is set or not.
: So your program flow could check bit-7
: TEST AL,10000000b
: JNZ BIT-7isSET ; jump if bit is set
: OR AL,AL
: JS BIT-7isSET ; this works too
: Many programs treat signed bytes/words differently (maybe?).
: If bit-7 is set, it's a minus number (er vice/versa)
: If bit-7 is set, it's less than 128 = clear bit-7 & use bits 0-6 ?
: If bit-7 is set, it's greater than 127 = unsigned
: So figgure out what your program is using them for and process them accordingly.
: You can change signed to unsigned then ADD SUB DIV etc
: Or if bit-7 = set subtract the minus number? (bits 0-6)
: So bit-7 is actually a toggle indicator & bits 0-6 holds the value.
: AND AL,01111111b ; keeps bits 0-6
: I've seen the following used under certian conditions
: AND AL,10000000b ; zero out bits 0-6
: JZ ITsSIGNED ;then it jumps if it's signed (maybe it's JS?)
: Check an Intel opt code doc for signed specfic instructions & work with your signed numbers according to your programs use & the instructions available.
: Make small .com file, check small code snipits, use the good ones.
: Make/get a Binary printer to show your output.
: TOP:
: SHL AL,1
: JC PRINT_A_1 ; jump and print a 1, loop back to TOP CX=8 times
: PRINT_A_0: ; print a 0 here, repeat loop thingie
:
: I don't know what type of ASCII number you want printed?
: HEX, DECIMAL, BINARY, OCTAL, ?
: But I have some printer proc's made for Nasm in C:
asminc16 at
: http://bitdog.home.att.net/file/nasmenv.zip
: Do anything you want with my stuff in there.
: Describing a converter/printer here would be huge, as would be includeing working code.
: I hope that helps somehow.
: And if any one has corrections or info to add, please feel free to post.
: Bitdog
: [/green]
:
:

Hey, thanks for the reply!!! Yeah, I think your code might work for me. About outputting to the screen in ASCII, I really should have said 8-bit binary format (ex. 00000001 + 00000010 = 00000011 output to screen). I assume that I can do the calculations with the two numbers and then output the result to the screen. Since I am fairly new to assembly, does anyone have some sample programs with code snippets on getting user input strings from the keyboard, storing them, perform calcs, then output? I am sure that if I could see some sample code I would be able to find the solution more easily and understand it better. You guys are great...thanks for the help!!!

Kris
• you can find several samples that can do input/output in pure binary here:

http://www.emu8086.com/vb/index_asm.html

Take a look at "ToBin" and "Bin2Dec" examples.

after you input a number, it is conveted to a value in register (AL for example), then you may just add those using simple "ADD" instruction.

• : you can find several samples that can do input/output in pure binary here:
:
: http://www.emu8086.com/vb/index_asm.html
:
: Take a look at "ToBin" and "Bin2Dec" examples.
:
:
: after you input a number, it is conveted to a value in register (AL for example), then you may just add those using simple "ADD" instruction.
:
:
:
:
:

Thanks for all the info guys!!! I'm working with it right now. EMu8086 is great huh??? Really cool prog...

Kris