繁体   English   中英

将 Arduino 代码转换为我的项目的汇编代码 [关闭]

[英]Converting Arduino code to assembly code for my project [closed]

我正在做一个来自 Arduino C 的汇编代码,这是我第一次使用汇编,我遇到了困难,但我想它仍然缺少 for 循环中的一些命令? 你能帮我么....

我花了很多天,但我仍然是组装的新手。 顺便说一句,我使用视觉工作室 7

我只分享到 void setup,但还没有 void loop,因为我必须完成这个问题然后我继续下一个。

在 arduino C 代码中:

const int echoPin = 2; 
const int trigPin = 3;
const int red = 0;
const int yellow = 1;
const int green = 2;
long duration; // variable for the duration of sound wave travel
int distance; // variable for the distance measurement


int Traffic_Light_A[] = {13,12,11};   // Traffic light (A) on the right side (Red, Yellow and Green)
int Traffic_Light_B[] = {10,9,8};  // Traffic light (B) on the left side(Red, Yellow and Green)
int Traffic_Light_C[] = {7,6,5};   // Traffic light (C) on the side road(Red, Yellow and Green)

void setup() 
{
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT
  pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT
  for (int i = 0; i < 3; i++)
  {
    pinMode(Traffic_Light_A[i], OUTPUT); 
    pinMode(Traffic_Light_B[i], OUTPUT);
    pinMode(Traffic_Light_C[i], OUTPUT);
  }  
  for (int i = 0; i < 3; i++) // Turn off all lights
  {
    digitalWrite(Traffic_Light_A[i], LOW); 
    digitalWrite(Traffic_Light_B[i], LOW);
    digitalWrite(Traffic_Light_C[i], LOW);
  }
}

在汇编代码中:

start:
;set pins 2-3 to high
ldi r17, (1<<PD2)|(1<<PD3)  
out PORTD, r17
;set pins 5-13 as output
sbi DDRD, 5
sbi DDRD, 6
sbi DDRD, 7
sbi DDRB, 0
sbi DDRB, 1
sbi DDRB, 2
sbi DDRB, 3
sbi DDRB, 4
sbi DDRB, 5
; pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT
;pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT
DDRB = 1<<DDB2
DDRB = 1<<DDB2
;for statement
CLR r17
LDI R16, 0
Top: CPI R16, 3
BRGE Exit
ADD R17, R16
INC R16
JMP Top
Exit: NOP

;for statement
CLR r17
LDI R16, 0
Top: CPI R16, 3
BRGE Exit
ADD R17, R16
INC R16
JMP Top
Exit: NOP

loop:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM