Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a subroutine that compares the 8-bit two\'s complement numbers in two tabl

ID: 643859 • Letter: W

Question

Write a subroutine that compares the 8-bit two's complement numbers in two tables. It should determine whether all the numbers in the first table are equal to or greater than the corresponding numbers in the second table. The subroutine should return 00 in the A accumulator if the condition is false and FF if it is true. The refrences to the tables should be passed in the X and Y registers and the table length should be in the A accumulator.

Keep answer as simple as possible.

Answer with pictures (screenshots) please, using THRSIM11

Explanation / Answer

The numbers in the most processors are already encoded as two's complement and there is no need to "convert" them. And in general, "two's complement" is a human interpretation of the numbers.

Another deal is if you want to compute the negative number of the given (that is what two's complement actually is) i.e. you need y = -x.

In many platforms such easy operation is implemented by special instruction and there is no need to use a function:

; x86

neg al

On the CPUs where neg instruction is not available it is still very easy to be implemented by 2 instructions:

; pseudo cpu

not reg8

inc reg8

; or

xor reg8, 0ffh

add reg8, 1

; or any other combination available

Why this operation is not suitable to be implemented as a subroutine? Such subroutine will look like:

; al contains the argument and return the result.

twoscom:

neg al

ret

Then if you want to use it to compute the two's complement of cl, you have to:

mov al, cl

call twoscom

This way you execute 4 instructions that are 8 bytes long on 16bit program and 10bytes on 32bit, and what is worse, affect memory read write (stack operations of call/ret) instead of single instruction:

neg cl ; always 2 bytes and memory access.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote