DEV Community

Anja
Anja

Posted on

Introduction to Assembly

Hello!

Lets have a look at the Assembly language. Assembly is one level above binary, which runs on your hardware. The Assembler converts Assembly into binary. In the following 'Hello World' code we are working with the registers of a Raspberry Pi, which are contained in the CPU and can hold up to 32 bits.

This is the code:

.global _start
_start:

MOV R7, #4 //System call to output to screen
MOV R0, #1 //Set monitor as output stream
MOV R2, #12 //String Length
LDR R1, =message //Load register with address of string
SWI 0 //Software interrupt

end:
MOV R7, #1
SWI 0 //This combined with line above:Software interrupt,
      //saying to return to the terminal

.data //Signify that what follows is data
message:
.ascii "Hello World\n"
Enter fullscreen mode Exit fullscreen mode

MOV R7, #4 means, that we put a 4 into the register 7 and it tells the System to output something on the screen. LDR means "load" and inside R7 there will be saved the starting adress of the String "message". SWI is the so called software interrupt function.

A software interrupt sends a signal to the Operating System. When it receives this interrupt signal it will check the values which are in the registers R0 and R7 and act accordingly, printing Hello World to the screen. After this it continues with the following lines in the code and returns to the terminal.

Did you work with Assembly yet and what did you program? Have a nice day. :)

Sources: https://www.youtube.com/watch?v=ViNnfoE56V8&feature=youtu.be

Top comments (4)

Collapse
 
lealsdev profile image
Leandro Alves Santos

Hello Anja. Great article!
I always have interest in assembly development.
I did a course on how to program for Atari VCS 2600 and I wrote a code to draw the pacman character and move it with the joystick.

github.com/lealsdev/AssemblyStudie...

It is very simple, but I really liked the result.

Have a nice day!

Collapse
 
anja profile image
Anja

Hi Leandro, thank you! 😊 That's great that you programmed pacman for the Atari! 😊 👏 I didn't program with assembly yet and only learned some basics out of curiosity. 😊 Have a great day too! 🙌

Collapse
 
yellow1912 profile image
yellow1912

I took a course in assembly because it was compulsory. I admire anyone who can code it fluently. You guys have a special gift for sure. This language is really not for the normal, average humans.

Collapse
 
anja profile image
Anja

Hi, that's great that you had a course about it!😊 I didn't program with it yet and only learned some very basics. Yes it seems more challenging than languages like python so it's a nice skill to have for sure. 👍