News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

shifting in a HL

Started by jack, October 25, 2024, 09:49:18 AM

Previous topic - Next topic

jack

I am having a hard time with bit shifting, I hope that it's ok to post my question here as it's not Masm related
I am trying to rewrite my MP math routines using 16-bit integers instead of 32-bit and I need to be able to shift an array of 16-bit integers with carry in and out, I got some code produced by AI but am not sure the result is correct
suppose that you have n =  1010101010101000 and carry = 11, what's the correct value if n is shifted left by 5 ?
I am getting 0101010100110000 but that doesn't look right, shouldn't it be 0101010100011000 ?
I realize that normally a carry is either 0 or 1 but I am programming in a HL

NoCforMe

I get:

n:       1010101010101000
n SHL 5: 0101010100000000   ;5 bits fall off left end, 5 0s shifted in @ right

Now I'm not sure what's supposed to happen with the carry bits. If the carry is 11, then I suppose they just get put in at the right like so:

0101010100000011

(basically just ORed in)

Does this look right?
Assembly language programming should be fun. That's why I do it.

zedd151

Can you inline some assembly code? Or is that not an option?

NoCforMe

He doesn't need any assembly code, just the right recipe for doing what he wants to do. Same in a HLL as in any other languge.

I'm not sure at all how those carry bits are supposed to be handled. Do they get shifted in as well, or tacked on after the shift?
Assembly language programming should be fun. That's why I do it.

zedd151

Quote from: NoCforMe on October 25, 2024, 10:40:44 AMHe doesn't need any assembly code...
Maybe, but this is an assembly code related forum, I felt obligated to ask that question. Plus, he could then post his code and probably get more responses.  :biggrin:  Assembly is much more understandable for some of us.  :tongue:
So jack, what language are you working with? Isn't 'carry' a Boolean? (I.e., Either 1 or zero) If not, why? Is it the value to carry, and not a flag? Without seeing the code, so many questions...

sinsi

If you have working code using 32-bit integers can you post that at least?
For an ASM programmer, carry has a specific meaning and is 1 bit, not 2 like you are showing.

Are you trying to shift the whole array left and propagating the "carry" bits?

This is the opposite of TMI :biggrin: TLI?

six_L

QuoteBin: 10101010-10101000
Hex: AAA8h
--------------------------------------------------------------------------------------------
shl ax,5
Bin: 01010101-00000000
Hex: 5500h
--------------------------------------------------------------------------------------------
rol ax,5
Bin: 01010101-00010101
Hex: 5515h
--------------------------------------------------------------------------------------------
rcl ax,5
Bin: 01010101-00001010
Hex: 550Ah
--------------------------------------------------------------------------------------------
sal ax,5
Bin: 01010101-00000000
Hex: 5500h
--------------------------------------------------------------------------------------------
Say you, Say me, Say the codes together for ever.

NoCforMe

Assembly language programming should be fun. That's why I do it.

jack

hi everyone and thanks for the replies, sinsi, yes I want treat an array of 16-bit integers as a huge register, sorry for being late, I was very busy
but I think that I solved the problem, thanks again  :azn:

NoCforMe

So what about that weird carry (2 bits)? Can you explain how that fits into the scheme? We're all curious here.
Assembly language programming should be fun. That's why I do it.