1

I've noticed that the instruction set has an LSL (logical left shift), which does r << 1 (left shifts the register by 1). I'd like to be able to left shift by an arbitrary number. Do I need to do this in a loop, or is there a single instruction that would do this for me?

I imagine the reason for only shifting 1 bit is so that the carry is always OK, but in my case I will bit shifting 8 bit unsigned numbers a maximum of 8 bits to the left, to get unsigned 16 bit numbers... so I think I should be OK?

Thanks,

z.

ps full disclosure: I'm a student, but this is a small part of an assignment. The assignment is to implement multiplication without MUL. I imagine that I am expected to do multiple additions in a loop... but I wanted to do something different. So I am implementing it recursively with bit shifting! This is just one of the stumbling blocks on the road to my solution.

Tim
  • 35,413
  • 11
  • 95
  • 121
Ziggy
  • 21,845
  • 28
  • 75
  • 104
  • 4
    Shifting by a single bit at a time is entirely sufficient for implementing multiplication (as in: even if you have multi-bit shifts, you don't normally need/use them to implement multiplication). – Jerry Coffin Sep 17 '12 at 01:54
  • Getting @Jerry's comment to work will bring you face to face with the old adage about many problems being solvable with another layer of caching (and most of the others with another layer of indirection, but that is another story). – dmckee --- ex-moderator kitten Sep 17 '12 at 02:11
  • Does HC12 let you swap the bytes in a 16-bit word? Maybe load the high half of a register with its low half (like `mov ah, al` would do in x86)? – nneonneo Sep 17 '12 at 02:47
  • 2
    Web search quickly gives links to the instruction set. Why not read it and see if there is a single instruction that can do what you need? – Alexey Frunze Sep 17 '12 at 05:47
  • @alexey yeah I have both the full glossary and the abridged instruction. I was just hoping that I had missed something. – Ziggy Sep 17 '12 at 17:02

0 Answers0