+ 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
19 Respuestas
+ 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.
+ 11
I'd love to assist by putting myself through a crash course on ARM Assembly (Cortex-M0 Instruction Set). But, I don't have more time than I've just spent on doing some light research.
That said, I'm sharing my relevant notes for anyone interested in giving this a go.
That is assuming Brian isn't able to get you through this.
----
My sad attempt at decompiling online using an ARM compiler:
--
https://godbolt.org/z/9cnTo5
----
References that Seemed Most Relevant:
--
https://azeria-labs.com/downloads/Slides-SAS_final.pdf
https://azm.azerialabs.com/
https://developer.arm.com/documentation/ddi0432/c/programmers-model/instruction-set-summary
https://developer.arm.com/documentation/dui0662/b/The-Cortex-M0--Instruction-Set/Instruction-set-summary
https://developer.arm.com/documentation/dui0473/m/writing-arm-assembly-language
https://developer.arm.com/documentation/100748/0611/getting-started/compiling-a-hello-world-example?lang=en
http://users.ece.utexas.edu/~valvano/EE345M/Arm_EE382N_4.pdf
https://en.wikipedia.org/wiki/ARM_architecture
http://www.toves.org/books/arm/
https://salmanarif.bitbucket.io/visual/
https://salmanarif.bitbucket.io/visual/supported_instructions.html
----
Best of luck to you on this!
+ 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.
+ 5
Martin Taylor where do BIOS.COM and COMMAND.COM come from?
+ 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".
+ 4
Is the label missing a colon?
done:
B done
+ 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.
+ 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.
+ 2
please answering my question .
+ 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
+ 2
I'M JUST GETTING ERROR ON FIRST (done)
.what's the problem with it?
+ 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