Please Help Me With My 8086 Asm Programming Class!


Jaguarandine

Member
Joined
Jun 14, 2006
Messages
245
I have quiz today and program due today at 8:30pm PST and I'm lost in some concepts. I'll just start going down my list of things if anyone feels like helping. Thanks!

1) signed numbers?
-I understand that 16-bit unsigned numbers (0-65535) must be split in half (0-32767 is positive, and 32768-65535 is negative) for signed numbers. But how it is all implemented? And how does "overflow" work?

2) ASCII text to hex numbers - (basically user inputs base 10 numbers (0-9) which is stored in ASCII format in a register. It's then converted to hexadecimal)
-As I understand it there are 2 steps, converting the ASCII to binary, then the binary to hex. What's
the basic logic behind this?
-ASCII character minus '0' will give you an actual number, right?

3) ADC, SBB, SBW, CWD
-I'm a little confused on these commands

4) What's the SI (Source Index) register exactly? How is it used?

5) Two's compliment?

6) any tips on the stack? I know last-in-first-out, push, and pop. Any other crucial concepts?


I hope I'm not asking for too much and my post made sense. Thanks for your help guys. I really appreciate it. Off to my morning classes!
 
Did they teach you anything before setting the work? :p I don't really know a lot about the 8086, but I can help with the more generic questions.

1) I don't know for certain, but I didn't think the processor itself had 'negatives' as a special value. You chose a method of representing the negatives and the method you choose determines how you deal with them in your code. See question 5. Overflow is where you exceed what the space can hold and it just loops back around to the start (or the end if you are subtracting).

2) The processor does not convert ASCII to binary, nor hex to binary. ASCII is basically a lookup table assigning values to various characters and control codes. Hex and binary are different number systems, but having a number in hex, does not make it different to the equivalent in binary, they are both just ways of representing a number (it just so happens that hex and binary go nicely together because one hex digit is equivalent to 4 bits).

And yes, you can take an ASCII representation of a number and subtract the value of the '0' character to convert to an integer. However, you clearly need to check the value is within the range used for numbers in ASCII (i.e. 0x30 to 0x39).

5) Two's complement one of several ways of representing signed values. Basically, the MSB indicates the sign (low meaning positive, high meaning negative), and the rest of the bits are the value (i.e. magnitude of the number). For 0, all bits are 0, and to go up into positive integers, you simply count up as normal in binary up to the limit of the space available. If you go down one from 0 to -1, the MSB goes high to indicate a negative value, all the value bits are high and you begin counting as before, except all the bits are inverted.

Thus, for an 8 bit signed integer:
CODE

Hex Binary Decimal
0x03 00000011 3
0x02 00000010 2
0x01 00000001 1
0x00 00000000 0
0xFF 11111111 -1
0xFE 11111110 -2
0xFD 11111101 -3
0xFC 11111100 -4


The negative values are a bit like a mirror image of the positive ones, just remember that the MSB represents the sign, not the magnitude of the value stored. It is useful because it is a representation you can use normal addition and subtraction instructions upon without having dedicated circuits for handling negative numbers and there is only one representation of 0 (in one's complement, the negatives are a complete mirror image of the positives, so you have both 0xFF and 0x00 representing minus and plus 0 respectively).
 
Except it's wrong. <_<

The over flow from the eighth bit is the 'carry' flag

a carry from the seventh bit is an 'overflow' and shows the two's complement value has overflowed into, and changed the eighth bit.

I'll have to some digging to check the logic of it :/

A second exercise would be adding larger numbers, say 80 + 90, or -80 + -90
(0x50 + 0x5A, 0xB0 + 0xA6) and watching what happens to bits 7, 8 & 9
 
As I understand it, an overflow happens in a signed number like so:

01111110 (126)
01111111 (127)
10000000 (-127)
10000001 (-126)
 
I just skimmed through, so I'll not answer everything. I once programmed a 8086 emulator, so I might be able to answer some questions. :p

A signed word (16-bit) in the 8086 has bit 15 set (0 is the rightmost bit and 15 the leftmost).

Overflow. For example, if you add two words (AX + BX) and the result is too large to fit in a word, the carry flag and the overflow flag will be set (CF and OF).

When you use ADC AX, BX for example what you're really doing is AX = AX + BX + CF (carry flag). ADC is useful for additions larger than 16-bits on the 8086.

Sorry, I read and wrote this in a rush.

Edit:

Just to answer someone above, the carry of the 8th bit in the addition of 16bit words is the auxiliary flag, not the overflow flag.
 
Now I have some time, as I'm no longer at work.

1) signed numbers?

Any number with its most significative bit (sign bit) set to 1 is negative (when working with signed numbers).
Overflow. Every time you do an operation and the result is too large for the destination register, overflow occurs.

2) ASCII text to hex numbers - (basically user inputs base 10 numbers (0-9) which is stored in ASCII format in a register. It's then converted to hexadecimal)
There's no conversion, a number is a number either in decimal or hexadecimal representation. For example the code for 'P' in ASCII is 50h (hexa) = 80 (decimal). The CPU doesn't convert anything, for it a number is a number whatever the representation.
When you want to convert ASCII number characters to the numerical equivalents they represent you subtract the ASCII code for '0' from their codes because '0' (ASCII 30h) - '0' (30h again) equals 0, '1' (ASCII 31h) - '0' (30h) equals 1, and so on... decimal, hexadecimal, octal, binary, it's all the same...

3) ADC, SBB, SBW, CWD
ADC -> Add With Carry : Destination = Source + Destination + Carry flag (Used for additions larger than the available registers)
SBB -> Subtract with borrow : Destination = Destination - Source - Carry flag (Used for subtractions that give a result larger than the available registers, large negative numbers for instance)
SBW -> Never heard of this instruction before :huh:
CWD -> Convert word to doubleword : This instruction is 386+ only, and what it does is to convert a word value (16 bit) to a doubleword (32 bit), including extending the sign values (the signal is preserved).

4) What's the SI (Source Index) register exactly? How is it used?
SI is usually used with DS (DS:SI) to copy, compare, test, add, etc... values in memory locations in REPx loops (together with ES:DI). This register is simply a pointer into a memory location (just like DI, BP, SP, IP, but each has it's uses).

5) Two's compliment?
Don't remember, it's been a while since I used this... :p

6) any tips on the stack? I know last-in-first-out, push, and pop. Any other crucial concepts?
Not really. Whenever you use CALL ou a interrupt is invoked, the return addresses are stored in the stack. You have to be careful when using the stack in these cases.

If you need anything more detailed, please just ask :)
 
Thanks everyone for your responses. They really helped me today.

During the test, I was sure I was going to get 100% correct. But I neglected a few important points:
-I confused dw (word) with dd (double word). Really stupid I know
-There was a fill in the stack problem in which I neglected to look at the addresses of memory on the stack.

I realized my mistakes as soon as I finished the test. Hopefully I still did ok.

Thanks again for your help.
 
BlueAchenar said:
Just to answer someone above, the carry of the 8th bit in the addition of 16bit words is the auxiliary flag, not the overflow flag.
:unsure: Umm Yeah. The last time I had to worry about overflow, carry, etc was on 8-bit systems ;) so that was where I was coming from. I should have specified word-size :ph34r:
 
Last edited by a moderator:
Back
Top