Lexy Feito
Lexy Feito

Reputation: 290

How to implement a logical shift (to the left) by 8 bits?

I am trying to determine how to shift the last 8 bits (i.e. byte) of a 16 bit (two byte) word to the left using the LC-3 instruction set.

For example,

0000 0000 1111 1111 -> 1111 1111 0000 0000

Upvotes: 0

Views: 10852

Answers (2)

Nexion
Nexion

Reputation: 433

To do a left shift all you have to do is add the value to itself. Create a simple loop to do this 8 times.

Something like

LD R1, count
loop
    LD R0, word
    ADD R0, R0, R0 ;Left Shift
    ADD R1, R1, -1 ;Decrement shift counter
    BRp loop       ;We still have shifts, go back to loop

HALT
count .fill #8

Upvotes: 2

Jordan Dea-Mattson
Jordan Dea-Mattson

Reputation: 5821

Now understanding that you are talking about LC-3, I found the LC-3b Miroarchitecture and this presentation on the Instruction Set referenced.

You need to implement a logical shift. Specifically a logical shift left. A number of ways are available to do this.

If you understand binary arithmetic, you will be able to do this in a straightforward way.

Upvotes: 1

Related Questions