Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Need to learn ARM assembly for Pi B for compile

This thread is locked; no one can reply to it. rss feed Print
Need to learn ARM assembly for Pi B for compile
Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Hey for my class, I'm writing a compiler, and I need to learn assembly, specifically ARM assembly for the Raspberry PI Model B. That is our target architecture.

If I can take our source language, and turn it into arm assembly, I win. We can use gcc to objectify our assembly and link it.

What is the best way to go about learning assembly language? What is relevant these days? Are there any good tutorials for this?

I'm going to be buying or renting a Raspberry PI to test this on, as we need a working model with at least some small subset of the language compiling and executing properly. Personally I would be happy if I could write a simple text calculator app in my source language and run it through my compiler and produce ARM assembly for gcc to link.

Perhaps I should start by compiling simple c code and looking at the generated assembly code. That might be a good way to learn.

Chris Katko
Member #1,881
January 2002
avatar

Raspberry PI

They're super cheap.

Assembly also hasn't changed in... like ever.

x86 is still almost entirely in x64 (except without insane real-mode addressing with jump + jump * indirect_jump / heat_death_of_universe addressing modes). It just has more registers and a flat address space (well, plus virtual addressing).

It's really not that bad. You can start with C/C++ and embed assembly code inside a function with __asm{} or whatever and that way C/C++ handles all the original memory/etc setup code.

Then as you're more comfortable, try one from scratch.

Also, disassemble a simple C program you wrote. (Or use one of the many great online sites that do it for you. Like Godbolt. You can compare the assembly different compiler options, different compilers, etc.)

https://godbolt.org/

Notice you can compare (with the same compiler) the assembly of DIFFERENT architectures like MIPS/ARM.

#SelectExpand
1 2// Type your code here, or load an example. 3int square(int num) { 4 return num * num; 5} 6 7 8X64 GCC: 9 10square(int): 11 push rbp 12 mov rbp, rsp 13 mov DWORD PTR [rbp-4], edi 14 mov eax, DWORD PTR [rbp-4] 15 imul eax, eax 16 pop rbp 17 ret 18 19ARM GCC: 20 21square(int): 22 str fp, [sp, #-4]! 23 add fp, sp, #0 24 sub sp, sp, #12 25 str r0, [fp, #-8] 26 ldr r3, [fp, #-8] 27 ldr r2, [fp, #-8] 28 mul r1, r2, r3 29 mov r3, r1 30 mov r0, r3 31 add sp, fp, #0 32 ldr fp, [sp], #4 33 bx lr

Basically, exposure exposure exposure. And playing around with it. Change one thing, see the code change, Google the new commands.

For example, I've never read ARM in my life. Well, there's some code. Now to start googling:

http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0552a/BABFGBDD.html

"str" = "store"

Looks like it may be an orthogonal architecture with explicit load/store commands instead of implied registers (IIRC, X86).

From what I've heard, ARM is WAY easier to understand than x86. (As was the Mac 68000 assembler. WAY more orthogonal architecture. That is, every command works in every scenario. )

Like, floating-point and MMX occupy the same registers and you can only use vector OR floating point numbers at the same time without a super expensive context switch? Really guys? RLY? (Maybe newest SSE doesnt have that problem, I don't remember.)

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Go to: