I am currently writing some assembly code that needs to address different I/O ports at certain times in my code. For example, at one point I may want to address PORTD4, and at another point I may want to address PORTB6. The solution that I have come up with is the following...
;Get the port number
ldi xl, lo8(port)
ldi xh, hi8(port)
ld r18, x
;Figure out which port "section" is being used, use the flags here
sbic flags, B_flag
rjmp B_port_one_on
rjmp D_port_one_on
B_port_one_on:
out PORTB, r18
rjmp one_delay
D_port_one_on:
out PORTD, r18
one_delay:
This solution is okay, but I'm trying to come up with something faster. The timing in my project is crucial and although this does work, I want to give myself a little bit more elbow room. One "solution" that I want to try to implement is instead of using a sbic
function and then using rjmp
, I want to see if I can store the I/O port location in a register or in a byte of RAM. Then what I want to do is load that location and then use the out
function to load both the port letter and number from those registers/bytes of information. As you can see, I have already done so with the port number. Now I need some way of loading the I/O address via a register or byte of memory. I have tried setting it as a register and used the X registers to load the port address, but both have come back with errors. Is what I want to do even possible or am I just going to have to deal with what I've got? (The MCU that I am using is the ATTINY4313 @20Mhz)