import time
time.sleep(0.1) # Wait for USB to become ready

print("Hello, Pi Pico!")
'''Using the web page context as the primary source of information.
do not use movwt
varify maximum value of constants for each instruction
mul uses 2 parameters mul(dest,source) # dest = dest & source
create a function using micropython.asm_thumb. convert this code: 


'''


@micropython.asm_thumb
def fill_memory(r0, r1, r2):
    # r0: pointer to memory
    # r1: number of bytes to fill
    # r2: value to fill with
    label(LOOP)
    strb(r2, [r0, 0]) # store value at memory location
    add(r0, r0, 1) # increment pointer
    sub(r1, r1, 1) # decrement counter
    bne(LOOP) # repeat until counter is zero

@micropython.asm_thumb
def reverse_memory(r0, r1):
    # r0: pointer to memory
    # r1: number of bytes to reverse
    mov(r2, r0) # copy pointer to r2
    add(r3, r0, r1) # add number of bytes to r0 and store in r3
    sub(r3, r3, 1) # decrement r3 by 1
    label(LOOP)
    cmp(r2, r3) # compare pointers
    bge(DONE) # if r2 >= r3, exit loop
    ldrb(r4, [r2, 0]) # load byte from r2 to r4
    ldrb(r5, [r3, 0]) # load byte from r3 to r5
    strb(r5, [r2, 0]) # store byte from r5 to r2
    strb(r4, [r3, 0]) # store byte from r4 to r3
    add(r2, r2, 1) # increment r2
    sub(r3, r3, 1) # decrement r3
    b(LOOP) # repeat loop
    label(DONE)



MAXSCREEN_X = const(160)
MAXSCREEN_Y = const(128)
@micropython.viper
def rectangle(x:int,y:int,width:int,height:int):
    screen = ptr16(LCD.buffer)
    for i in range(height): # loop over the height
        for j in range(width): # loop over the width
            address = int((y + i) * MAXSCREEN_X + (x + j)) # calculate the address of each pixel
            screen[address] = 0xffff # color white

memory = bytearray([0,1,2,3,4,5,6,7,8,9])
    
print(memory)
reverse_memory(memory,10)
print(memory)
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT