2

I am working on a problem for my introductory computer organization course at UCI and we use x86 assembly language in the course (using Visual Studio and the MS syntax). While the problem is for a homework assignment, we are graded on attempts and not the correctness of our answers.

My question is w.r.t indirect memory addressing. The entire question is stated below:

Suppose EBX = 1000 (in decimal) and the byte values stored in the memory addresses 1000 through 1003 are 255, 255, 255, and 255 (in decimal). What effect do the following instructions have (independently) on this area of memory? Assume for multi-byte data, least significant byte is stored in smallest address.

a. ADD byte ptr [EBX], 1

   ADDRESS | Before | After
     1000  |  255   |          ; The After column is where we place our answers.
     1001  |  255   |          ; All of these values are unsigned
     1002  |  255   |
     1003  |  255   |

b. ADD word ptr [EBX], 1

   ADDRESS | Before | After
     1000  |  255   |   
     1001  |  255   |    
     1002  |  255   |
     1003  |  255   |

c. ADD dword ptr [EBX], 1

   ADDRESS | Before | After
     1000  |  255   |   
     1001  |  255   |    
     1002  |  255   |
     1003  |  255   |

I understand that byte ptr [EBX] will load the value 0xFF and that question (A) essentially boils down to ADD 0xFF, 0x01 using a memory address of one byte. However, what I do not understand is how to deal with the overflow caused by '0x100' which would require a minimum of 9 bits to represent.

The two possible solutions I can determine for question (A) ADD byte ptr [EBX], 1 are as follows:

   ADDRESS | Before | After
     1000  |  255   |  000    ; Overflow does not carry out to address 1001 and the most significant bit is lost
     1001  |  255   |  255
     1002  |  255   |  255
     1003  |  255   |  255

   ADDRESS | Before | After
     1000  |  255   |  000    ; Overflow overwrites the value in the next memory address
     1001  |  255   |  001    ; [base 10]
     1002  |  255   |  255
     1003  |  255   |  255

QUESTION: what effect does the overflow of representing a 9 bit result of an ADD operation in a single byte of memory have on any subsequent memory regions, if any

Any insight that anyone could shed on this topic would be greatly appreciated as I was not able to find any x86 specific information that dealt with the overflow of storing a 9 bit number in a single byte of memory.

4

1 回答 1

0

在每种情况下,从内存中检索的值(字节、字或双字)+1 将产生零并设置溢出标志,因为实际结果无法存储在可用空间中。该零将返回到内存,CPU 将在其状态寄存器中设置溢出位。设置溢出位的事实将允许执行操作作为结果 - 它不会影响存储到内存中的内容。

想想数百个单位(如果仍然教的话)。如果你有 9 并加 1,你会得到 0 并带有“溢出”。99+1 得到 00 +溢出;999+1 得到 000 +溢出

于 2015-02-10T02:26:45.187 回答