0

This is an assignment, I don't know where to start.

Assignment:

A byte can be represented using three octal digits. Bits 7 and 6 determines the left octal digit (which is never higher than 3); bits 5, 4 and 3 are the middle digit; and bits 2, 1 and 0 are the right digit.

For instance, 11010110 b is 11 010 110 b OR 326 oct. The value of a word is represented in split octal by applying the 2-3-3 system to the high-order and low-order bytes separately.

Write a procesure splitOctal that converts a word to a stringof exactly 7 characters representing the value of the number in split octal; two groups of three separated by a space.

Follow cdecl protocols. The procedure will have two parameters: 1) The word value (passed as the low order word of a doublewowd) 2) the address of the 7-byte-long destination string.

MODIFICATIONS: Instead of pushing the value convert as a word onto the stack, only use doublewords on the stack. So push the value to convert as a DOUBLEword onto the stack

I don't know where to start to accomplish this by shifting bits and rotating bits. Maybe give me some material to read, or a little kickstart?

GeekyDewd
  • 321
  • 1
  • 2
  • 18
  • 2
    What do you know? Does your textbook show how to shift and rotate bits, and if so, what does it say that you don't understand? Can you create the procedure definition with doubleword stack parameters, and at least show what you do know? Also, it might help if you specified which platform this assembly is for, since they are typically very different (I've worked with x86, x64, SPARC, PIC16F, Z80, IBM iSeries MI, and a few others). – Matt Jordan Apr 14 '16 at 21:56
  • 1
    I believe we're using 8086. I know how to shift and rotate bits. I do not understand how to get 3 bits to go to a certain register or named memory. – GeekyDewd Apr 14 '16 at 22:22

1 Answers1

1

Easy way:

convert hex -> 8bit integer by subtracting ASCII '0' or 'A', then left-shift the 4bit value from the first digit, and OR with the 4 bit value from the second digit.

Then convert that 8bit integer to octal by shifting/masking to extract the three sets of bits you want, and add '0' to each one.


More complicated way: don't combine into a single 8bit integer at any point. There are many ways to get the 4th bit from the first hex digit combined with the low two bits from the second hex digit. Your best bet might still involve an OR.


If you're actually targeting 8086, and not just normal x86, then shift-by-one and shift by CL are the only shifts you have available. So to shift by 4, you probably have to mov cl, 4 / shl al, cl, instead of just shl al, 4.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847