ASM Problem

Started by Deathwolf, February 25, 2011, 02:49:28 PM

Previous topic - Next topic

Deathwolf

stwu r1,-80(r1)     # make space free
stmw r14,8(r1)
lis r14,0x0000       # write 00000063 to r14
ori r14,r14,0x0063
lmw r14,8(r1)        # make space free
addi r1,r1,80
lis r12,0x8039       # load into address 8039F700 (Button)
ori r12,r12,0xF700
lhz r12,0(r12)        # read out 16 bit
cmpwi r12,0x1000 # button -
bne- THE_END       # if not pressed branch to THE END
stw r14,0(r3)        # if pressed, store value from r14 into r3.


THE_END:

stwx r0,r3,r4      # original instruction

code would be:
C2000000 00000007
9421FFB0 BDC10008
3DC00000 61CE0063
B9C10008 38210050
3D808039 618CF700
A18C0000 2C0C1000
40820008 91830000
7C03212E 00000000

I don't know what's wrong with this code.
Thanks for any help

EDIT: found the problem

lis r12,0x8039       # load into address 8039F700 (Button)
ori r12,r12,0xF700   # read out 16 bit
lhz r12,0(r12) # read out 16 bit
cmpwi r12,0x1000 # button -
bne- THE_END        # if not pressed branch to THE END
lis r14,0x0000    # write 00000063 to r14
ori r14,r14,0x0063
stw r14,0(r3) # if pressed, store value from r14 into r3.

THE_END:

stwx r0,r3,r4      # original instruction
lolz

Jackal

I am not very good at ASM but why load from stack into r14 after setting it to 0x63?

Deathwolf

#2
Quote from: Jackal on February 25, 2011, 03:13:14 PM
I am not very good at ASM but why load from stack into r14 after setting it to 0x63?
you meant this?

stwu r1,-80(r1)     # make space free
stmw r14,8(r1)
-------------------- ASM code
lmw r14,8(r1)        # make space free
addi r1,r1,80

that makes all registers (r14-r31) writeable.

stwu r1,-80(r1)     # make space free
stmw r14,8(r1)
lis r14,0x0000       # write value 00000063 to r14
ori r14,e14,0x0063
lmw r14,8(r1)        # make space free
addi r1,r1,80


lolz

Jackal

you new code make more sense to me with the lis and ori r14 towards the end

Deathwolf

Quote from: Jackal on February 25, 2011, 03:22:19 PM
you new code make more sense to me with the lis and ori r14 towards the end

normally the first code should work too but whatever.
lolz

strakn

Quote from: Deathwolf on February 25, 2011, 02:49:28 PM

lis r14,0x0000    # write 00000063 to r14
ori r14,r14,0x0063

I am new to asm too, but would it be simpler here to use

li r14, 0x0063

as that would clear the high 16 bits for you anyway

Deathwolf

Quote from: strakn on February 25, 2011, 04:50:58 PM
Quote from: Deathwolf on February 25, 2011, 02:49:28 PM

lis r14,0x0000    # write 00000063 to r14
ori r14,r14,0x0063

I am new to asm too, but would it be simpler here to use

li r14, 0x0063

as that would clear the high 16 bits for you anyway

the problem is, I have to use a 32 bit value because it needs a stw instruction.
but your idea was right so thank you^^
use li instand of 8 bit and 16 bit.
lolz

dcx2

li writes to all 32 bits.  it writes 0000 to the upper 16 bits.  it writes the operand to the lower 16 bits.  you can then use oris to mask in the upper 16 bits.

lis writes to all 32 bits.  it writes 0000 to the lower 16 bits.  it writes the operand to the upper 16 bits.  you can then use ori to mask in the lower 16 bits.

You didn't put your whole ASM code in the stack frame.  When you used lmw r14, it erased your 0x63.  That's why it didn't work.

Deathwolf

#8
Quote from: dcx2 on February 25, 2011, 06:00:44 PM
li writes to all 32 bits.  it writes 0000 to the upper 16 bits.  it writes the operand to the lower 16 bits.  you can then use oris to mask in the upper 16 bits.

lis writes to all 32 bits.  it writes 0000 to the lower 16 bits.  it writes the operand to the upper 16 bits.  you can then use ori to mask in the lower 16 bits.

You didn't put your whole ASM code in the stack frame.  When you used lmw r14, it erased your 0x63.  That's why it didn't work.

I didn't put the whole ASM code in the stack frame because it will freez with button activator.
how can I use it with the stack? I have no idea how it works.

btw sure, you already can use li for 32 bit
sth r14,3(r3)
lolz