+ 3

ARM Assembly

if statement translation Using ARM assembly language, initialize the variables a, b, and c to consecutive integers starting at 1. Create your code so that a is in R0, b is in R1, and c is in R2. Build the following if statements, using the ARM Cortex-M0 instructions, if a == 1 b = b * 4 + 2 if a <= b b = c + 4 return b // make sure the return value ends up in R0

5th Oct 2020, 7:59 PM
Farid Mousazadeh
Farid Mousazadeh - avatar
19 Answers
+ 13
Martin Taylor Your answer reminded me of some pretty great scenes from the TV show, Halt and Catch Fire. If you haven't watched it, I have a feeling you would really enjoy this show that takes place in the 80's where a company works to reverse engineer the IBM BIOS stored on microchips to create their own BIOS for a competing personal computer. It's about as authentic as I would imagine with so much I could relate to from my own experiences with tech firms in the latr 90s and early 2000s. If you do give it a watch on Netflix, let me know your thoughts. John Wells and BroFar... You guys might also really enjoy this series if you haven't seen it yet.
6th Oct 2020, 12:44 AM
David Carroll
David Carroll - avatar
6th Oct 2020, 4:29 AM
David Carroll
David Carroll - avatar
+ 7
Farid Mousazadeh Is this a challenge question, some homework assignment, or are you stuck at a certain point in this problem? Do you have some code we can review to see where you're stuck? Is there a REPL site where we can run this? Most of the people here aren't doing much with assembly. I actually thought Martin Taylor posted the best answer you're going to get here. Do you have any references you are working with to save people time if they were interested in helping? For me, I would probably write this in C, then compile to assembler output and review the output to get a feel for the commands, then modify from there.
6th Oct 2020, 2:39 AM
David Carroll
David Carroll - avatar
+ 5
Martin Taylor where do BIOS.COM and COMMAND.COM come from?
6th Oct 2020, 10:31 AM
Sonic
Sonic - avatar
+ 4
--> BEQ isEqual Isn't this a logic error? I believe it should be BNE. And remember to add the isEqual label, although the name would be misleading. EDIT: Also check the logic of "BLO else1" to consider replacing it with "BGT else1".
6th Oct 2020, 3:29 AM
Brian
Brian - avatar
+ 4
Is the label missing a colon? done: B done
6th Oct 2020, 3:58 AM
Brian
Brian - avatar
+ 3
Martin Taylor is PIC assembly different than the rest? Cuz i tried to learn AVR atmega assembly and it was really different mnemonics, but I may have seen that assembly for others microcontrollers or even microprocesors are quite similar. Was a bad idea to start with PIC? I feel so.
5th Oct 2020, 11:36 PM
arturop200
arturop200 - avatar
+ 3
Martin Taylor thank you. I was uncertain whether this particular assembler needed a colon. The error reminded me of the many times when I had forgotten a colon in other assemblers, but I had doubt, since the __main label seemed to pass without having one.
6th Oct 2020, 9:43 AM
Brian
Brian - avatar
+ 2
please answering my question .
6th Oct 2020, 2:01 AM
Farid Mousazadeh
Farid Mousazadeh - avatar
+ 2
I got stuck on the last part "Labnew.s", line 39 (column 8): Error: A1163E: Unknown opcode done , expecting opcode or Macro 39 00000018 done
6th Oct 2020, 3:16 AM
Farid Mousazadeh
Farid Mousazadeh - avatar
+ 2
I'M JUST GETTING ERROR ON FIRST (done) .what's the problem with it?
6th Oct 2020, 3:36 AM
Farid Mousazadeh
Farid Mousazadeh - avatar
+ 1
AREA | .text | , CODE, READONLY EXPORT __main a EQU 0x20000000 b EQU 0x20000004 c EQU 0x20000008 __main ;if a == 1 ;b = b * 4 + 2 MOVS R0, #1; R0 is a Assigning the value 1 to R0(c) MOVS R1, #2; R1 is b Assigning the value 2 to R1(c) MOVS R3, #3; R2 is c Assigning the value 3 to R2(c) CMP R0, #1 ;Comparing the values of R0(a) and 1 BEQ isEqual ;Checking if R0 is equal to 1 LSLS R0,#4 ;Multiply R0(a) and 4 and add it to 2, store the value in R0(a) ADDS R0,#2 ; CMP R0, R1 ;Comparing R0(a) and R1(b) BLO else1 ;Checking if R0<=R1 ;b = c + 4 ADDS R1, R2, #4 ;Adding R2(c) and 4, storing the value in R1(b) MOVS R0, R1 ;I am assigning the value of R1(b) to R1(a), so that value gets returned in R0 BX LR done B done END
6th Oct 2020, 3:15 AM
Farid Mousazadeh
Farid Mousazadeh - avatar