Assembly AVR汇编逻辑操作

Assembly AVR汇编逻辑操作,assembly,avr,Assembly,Avr,我在bigavr板上有atmega1280的以下汇编代码 ;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 .e

我在bigavr板上有atmega1280的以下汇编代码

;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          ; 7654 3210 (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
;将PA3:0设置为无上拉输入,将PA7:4设置为输出,并将PORTA7:4用于LED0-3。
诺利斯先生
.包括“m1280def.inc”
列表
.equ端口,端口
.equ DDR,DDRA
.equ PIN,PINA
.equ温度,0x10
.equ pa1,0x11
.equ pa2,0x12
.equ pa3,0x13
.第节.正文
格洛博梅因酒店
.org 0x0000
rjmp总管
主要内容:
主初始化堆栈ptr:
本地设计院温度,lo8(拉芒)
输出SPL,温度
本地设计院(ldi)温度,hi8(拉芒)
外滩
主初始化端口:
本地设计院温度,0x0
输出端口,温度
本地设计院温度,0xf0;76543210(门户索引)
输出DDR、temp;oooo iiii(输入/输出状态)
主回路:
在温度,针
安迪温度,0x0f
rcall set_led0
输出端口,温度
rjmp主回路

集_led0:;端口我在您发布的代码中没有看到任何
addi
指令。如果您的意思是
和i
,那么目的是屏蔽除感兴趣的位之外可能已设置的任何附加位


temp
设置为
PIN&0xf
,因此它可以具有0x0..0xf范围内的任何值。如果
temp
恰好是0xf,而您只是将
pa1
设置为
temp>>1
,那么您将得到0x7。但由于
准备操作数的意图似乎是将第n位放入
pa
n中,因此它会在移位后按位进行移位(例如0xf>>1==0x7,0x7&1==1)。

如果掩码的某个位置有位,则代码试图将0x1放入操作数中

首先,将pa1、pa2和pa3中的每一个移位不同的量,以将感兴趣的比特移到最右端。然后,“and with immediate 0x1”清除变量中除最右边以外的所有位,并保持最右边不变

变量将包含0x0或0x1,具体取决于感兴趣位的值