我在bigavr板上有atmega1280的以下汇编代码。AVR汇编逻辑运算
;Set PA3:0 to input without pull-up and PA7:4 to output and use PORTA7:4 for LED0-3.
.nolist
.include "m1280def.inc"
.list
.equ PORT, PORTA
.equ DDR, DDRA
.equ PIN, PINA
.equ temp, 0x10
.equ pa1, 0x11
.equ pa2, 0x12
.equ pa3, 0x13
.section .text
.globl main
.org 0x0000
rjmp main
main:
main_init_stack_ptr:
ldi temp, lo8(RAMEND)
out SPL, temp
ldi temp, hi8(RAMEND)
out SPH, temp
main_init_ports:
ldi temp, 0x0
out PORT, temp
ldi temp, 0xf0 ;(PORTA index)
out DDR, temp ; oooo iiii (i/o state)
main_loop:
in temp, PIN
andi temp, 0x0f
rcall set_led0
out PORT, temp
rjmp main_loop
set_led0: ; PORT << 4: (1 & 2) | 3
rcall prepare_operands
and pa1, pa2
or pa3, pa1
sbrs pa3, 0
ret
sbr temp, 0b00010000
ret
prepare_operands: ; move inputs 1..3 to pa1..3
mov pa1, temp ; and shift/mask them the LSB
mov pa2, temp
mov pa3, temp
lsr pa1
lsr pa2
lsr pa2
lsr pa3
lsr pa3
lsr pa3
andi pa1, 0x01
andi pa2, 0x01
andi pa3, 0x01
ret
的代码应执行逻辑运算:LED0: (PA1^PA2) v PA3
但我不明白它是如何工作的。 我的假设: With in temp, PIN
我可以读出输入引脚上的值。如果PORTA1和PORTA3被激活,PIN应返回00000101
。好吧,在prepare_operands
这是移动到变量pa1,pa2和pa3。对于pa1,它向右移动了一次。所以pa1包含00000010
。在pa1上执行addi
操作,为什么?这个怎么用?