def store_load_right_to_left(reg): AVR.POPZ() # idx + 48 AVR.STZ32(reg[5]) # store z AVR.STZ32(reg[2]) # store y AVR.SBIW(30, 8) AVR.STZ32(reg[4]) # store x AVR.STZ32(reg[1]) # store z AVR.SBIW(30, 8) AVR.STZ32(reg[3]) # store y AVR.STZ32(reg[0]) # store x reg = init_state() # reinit the state. # current idx is +8 AVR.ADIW(30, 8) # go to idx + 16 AVR.LDZ32(reg[1]) # load r[1] AVR.LDZ32(reg[4]) # load r[2] AVR.ADIW(30, 8) # skip the next 4 words as they contain garbage (former r[3]) AVR.LDZ32(reg[2]) # load r[4] AVR.LDZ32(reg[5]) # load r[5] # pop the initial values of the other half from the stack ! :p AVR.POP32(reg[0]) # load r[0] AVR.POP32(reg[3]) # load r[1] # current value of idx is +40 AVR.PUSHZ() return reg
def store(reg): AVR.POPZ() AVR.STZ32(reg[5]) # store z AVR.STZ32(reg[2]) # store y AVR.SBIW(30, 8) AVR.STZ32(reg[4]) # store x AVR.STZ32(reg[1]) # store z AVR.SBIW(30, 8) AVR.STZ32(reg[3]) # store y AVR.STZ32(reg[0]) # store x return reg
def stack_load_left_to_right(reg): AVR.POPZ() # idx + 48 AVR.PUSH32(reg[3]) AVR.PUSH32(reg[0]) # DO WE DO ONLY A SIMPLE REINIT OR A FULL ??? reg[0].sort() # we only re init the values in r[0] and r[3] reg[3].sort() # we only re init the values in r[0] and r[3] AVR.SBIW(30, 48) # go the begining of the state AVR.LDZ32(reg[0]) # load r[0] AVR.LDZ32(reg[3]) # load r[3] AVR.ADIW(30, 40) # go back to idx+48 : 4 + 4 + 16 + 16 AVR.PUSHZ() # push to the stack : idx + 48 return reg
def stack_load_right_to_left(reg): AVR.POPZ() # idx + 40 AVR.PUSH32(reg[3]) AVR.PUSH32(reg[0]) reg[3].sort() reg[0].sort() # reg = reinit_state(reg) # we only re init the values in r[0] and r[3] AVR.SBIW(30, 32) # skip the next two words AVR.LDZ32(reg[0]) # load r[0] AVR.LDZ32(reg[3]) # load r[3] AVR.ADIW(30, 24) # skip back 8 + 16 # current value of idx is +40 AVR.PUSHZ() return reg
AVR.CPI(28,0) AVR.BREQ('jspbxend') AVR.JMP('hopspx') AVR.LBL('jspbxend') AVR.JMP('spbxend') AVR.LBL('hopspx') AVR.PUSH(28) load() AVR.PUSHZ() AVR.JMP('spbox') AVR.LBL('spboxend') AVR.POPZ() store() AVR.ADIW(30,8) AVR.POP(28) AVR.DEC(28) AVR.JMP('spbx') AVR.LBL('spbxend') AVR.SBIW(30,16) # pop the constant of the round AVR.POP(28) AVR.LDI(27,3) AVR.AND(27,28)