Sie sehen gerade die Germany Version der Website.
Möchten Sie zu Ihrer lokalen Seite wechseln?
16 MIN LESEZEIT

ASSEMBLY LANGUAGE

Get coding on the Raspberry Pi 64-bit

John Schwartzman demos using assembly language code for the 64-bit Raspberry Pi to call Linux kernel services and the C run-time library.

Hello.c is the obligatory first program in C.

OUR EXPERT 

John Schwartzman is a long-time engineering consultant to business and government. He also teaches computer science at a local college.

Learning assembly language won’t make you a faster programmer (slower, more likely). However, it just might make you a better programmer. By learning just what a processor can and can’t do, you’re on the way to a deeper understanding of computer science.

Assembly language is a low-level language. It’s specific to a particular processor. You use it to program a specific processor at the hardware level. Compilers understand assembly language, because that’s what they use to create the instructions in high-level languages. Take a C++ compiler: it strings together lots of assembly language instructions to do its work.

Every kind of program ultimately executes machine language on the computer. Assembly language is simply machine language with mnemonics. Mnemonics are names given to machine language instructions, also known as op codes, so that we don’t have to remember hundreds of numeric values. It enables us to write a program using identifiers such as ADD, SUB and MOV.

Raspberry Pis can run in 32-bit mode (AArch32) or 64-bit mode (AArch64) depending on the OS. In this tutorial we’ll look at AArch64 and install a small 64-bit desktop machine on the Pi. The Pi is a Reduced Instruction Set Computer (RISC) that performs smaller and faster operations than a Complex Instruction Set Computer (CISC) like the Intel x86_64.

Making use of the kernel

We’re using Linux and so the assembly language we write will use Linux kernel services. Even when we use the C library (glibc), the library methods we call will, in many cases, be thin wrappers around the Linux kernel services. It’s become obligatory to introduce every new programming language with a program that prints “Hello, world!” to the console, so we’ll start there.

The screenshot (above) shows the program, hello.c and the screenshot (facing page) shows hello.asm, its AArch64 assembly language equivalent. At the command line in your hello working directory, type make release . Make invokes the gcc assembler to create the object file (hello.obj) from the hello.asm file and the LD GNU linker to create the executable (hello) from the object file. It also uses the GCC C compiler to build and link hello.c into the executable file a.out (assembler output).

The code

Get it from linuxformat. com/archives and on the DVD

The command make clean will remove all of the build artifacts from the working directory. The screenshot (page 90) shows the makefile for hello. Each project in this series has a similar makefile and all rely on the bash shell script named maketest.sh in the parent directory. There is also a makefile in the parent directory that will make or clean all of the child projects at once. Execute a.out and hello and satisfy yourself that they do produce the same output. $ make release // Build the program as -o hello.obj hello.asm # assemble ld hello.obj -o hello # link gcc hello.c # compile and link C version (a.out) $ ./a.out // Run the C executable $$$ Hello, world! $ ./hello // Run the ASM executable Hello, world!

Schalten Sie diesen Artikel und vieles mehr frei mit
Sie können genießen:
Genießen Sie diese Ausgabe in voller Länge
Sofortiger Zugang zu mehr als 600 Titeln
Tausende von früheren Ausgaben
Kein Vertrag und keine Verpflichtung
Versuch für €1.09
JETZT ABONNIEREN
30 Tage Zugang, dann einfach €11,99 / Monat. Jederzeit kündbar. Nur für neue Abonnenten.


Mehr erfahren
Pocketmags Plus
Pocketmags Plus

Dieser Artikel stammt aus...


View Issues
Linux Format
February 2021
ANSICHT IM LAGER

Andere Artikel in dieser Ausgabe


WELCOME
Year of the Linux…?
2021 is the year everyone can blast off
REGULARS AT A GLANCE
Red Hat kills off CentOS eight years early
DISTRO DRAMA
Google changes sign-ins
Google account sign-ins from embedded browser frames will be blocked from 4 January 2021
What now for 32-bit Linux?
Companies, distros and manufacturers are moving to 64-bit only support, so where does that leave 32-bit systems?
PAY THE MAN!
Keith Edmunds is MD of Tiger Computing Ltd,
INSTANT BIFROST
Alyssa Rosenzweig Software engineer, Collabora Since our previous
RISC-V smashes records
Micro Magic’s RISC-V-based CPU generates record-breaking results
Boost to Vulkan
Advanced lighting rolling out to the Vulkan graphics API
New NTFS driver
NTFS 3 kernel driver gets better compression features
Distro watch
What’s down the side of the free software sofa?
OPEN-ISH SOURCE?
Matt Yonkovit is Percona’s chief experience officer and
Kernel Watch
Jon Masters summarises the latest happenings in the Linux kernel, so you don’t have to
LOOKING FORWARD
Jon Masters has been involved with Linux for
Answers
Got a burning question about open source or the kernel? Whatever your level, email it to lxf.answers@futurenet.com
A QUICK REFERENCE TO… CRON
Computers are supposed to make life easier for
GET HELP NOW!
We’d love to try and answer any questions
Helpdex
shane_collinge@yahoo.com WRITE TO US Do you have a
Mailserver
Write to us at Linux Format, Future Publishing, Quay House, The Ambury, Bath BA1 1UA or lxf.letters@futurenet.com
BACK ISSUES
HotPicks
THE BEST NEW OPEN SOURCE SOFTWARE ON THE PLANET
SongRec
SHAZAM CLIENT
Xsuspender
PERFORMANCE TUNE-UP
WinApps
WINDOWS INTEGRATION
Dog
DNS CLIENT
AFTL
FILE TRANSFER TOOL
YUView
VIDEO PLAYER & ANALYSER
Micro-racing
RACING GAME
PixelDefence
TOWER DEFENCE GAME
Distribyted
TORRENT CLIENT
Topalias
ALIAS GENERATOR
On the disc
Ubuntu 20.04.1
START HERE
USING THE LXFDVD Using Linux for the first
Bodhi 5.1
DESKTOP SATORI MIN SPECS: 500MHZ CPU >> 512MB
AND MORE!
THE LXF LIBRARY
POWER-UP YOUR VMs
Orchestral (Virtual) Machines in the Docker is a terrible pun but here we are… we look at VM orchestration
REVIEWS
AMD Rade on RX 6800
The RX 6800 not only delivers 1,440p performance, it demolishes the RTX 2080 Ti at 4K, too says Jacob Ridley
Guix System v1.2.0
Strap in for this wild tour of the distro designed for the uber-geeks with your knowledgeable guide Mayank Sharma
Edge on Linux (dev)
Microsoft’s shiny new browser touches down on Linux. Mayank Sharma fires it up for a test drive… or will it become a voyage of discovery?
Feren OS 2020.11
Mayank Sharma discovers that this distribution is one of the best options to introduce new users to Linux. It’s time to spread the word!
Amnesia: Rebirth
Management refuses to go into the server dungeon, and for good reason – Leana Hafer has returned a changed woman
ROUNDUP
Astronomy software
If you’re a novice stargazer but clueless about how to feed your passion, Shashank Sharma knows a few tools to help you get started…
Customisations
Kicking things up a notch with even more databases and catalogues
Features
What can you do with and learn from these applications?
Usability
Balancing ease of use with functionality
Unique selling points
What makes these programs special?
Platform and hardware support
Will they work on your Linux distribution and device?
Search options
Can you look up coordinates and space objects?
Support and documentation
Is that a new star you’ve found, or just a speck of dust?
Astronomy software
The Verdict
Blast off with Linux
BLAST OFF
WITH LINUX!
Solid foundations
Start 2021 off on the right foot with a fresh install of Ubuntu 20.04 LTS, codename Focal Fossa
Install Ubuntu
Get Focal Fossa running on your machine, set up an incremental back-up regimen and start installing the huge free software ecosystem
Setting up disks
Keep your SSD cells tidy with regular trimming, then set up a RAID array for your static files and enjoy the simple pleasure of filesystem labels
Solve problems
In Linux, the best-laid schemes, to decontextualise Robbie Burns, gang aft a-gley. Get yer scheme gang glorious with oor troubleshooting guide
IN-DEPTH
RISE OF THE ROBOTS
Mats Tage Axelsson presents the basics of a robotics operating system and reveals what components can be used…
Next-gen terminals
Discover the next-gen terminal tools with David Rutland that will transform your command-line life
Pi USER
Elementary OS lands on the Raspberry Pi
The world is getting armed and dangerous, as another distro joins the Raspberry Pi army
Raspberry Pi OS updates
The final update of 2020 offers many improvements
SEEING IS BELIEVING
Andrew Gale produces a range of educational electronic
RetroPie 4.7.1
Les Pounder loves retrogaming and Raspberry Pi, so with RetroPie and the new Raspberry Pi 400 the question is: will he find his Nirvana?
Quickly install Manjaro on the Pi 4
MANJARO
Host Nextcloud 20 on a Raspberry Pi
NEXTCLOUD
TUTORIALS
Manipulate and work with PDF files
TERMINAL
Optimise your videos and free up HDD space
Nick Peers reveals how to convert your videos into H.264 and H.265 codec formats to help save drive space and maximise playback compatibility
Enhance your photos by stacking them
Combining multiple photos of the same scene using a stacking technique can result in some spectacular results, reveals Mike Bedford
Emulate classic Apple computers
Les Pounder goes back to his distant college days and reveals how to emulate the Apple desktop machines that he used for work and play
Getting to grips with Docker
People think of Docker as a server-room only tool, but as Michael Reed demonstrates, the platform has a lot to offer the general user, too
CODING ACADEMY
Remaking Angry Birds in Python
PYTHON
Chat
X
Pocketmags Unterstützung