element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Raspberry Pi Forum My First Assembly Program on a PI Zero2W
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
Raspberry Pi Wishlist
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 19 replies
  • Subscribers 662 subscribers
  • Views 4177 views
  • Users 0 members are here
Related

My First Assembly Program on a PI Zero2W

scottiebabe
scottiebabe over 3 years ago

I recently stumbled across this great ebook:

image

Available at: https://personal.utdallas.edu/~pervin/RPiA/RPiA.pdf

Following along the yellow brick road, I was able to get a basic program up and running. It takes two numbers as user input and calculates their sum. Thrilling! I know. Though kind of, as the addition is in double precision floating point and happening on the  VFP of the cortex-A53. I should note I am still using a 32-bit os on the pi, it will be interesting to see what changes when I move to the new 64-bit os.

.data
msg1: .asciz "Calculating A + B on the VFP\nInput A: "
msg2: .asciz "\nInput B: "
msg3: .asciz "\nResult =: %f\n"
scan_pattern : .asciz "%lf"

.balign 4
return: .word 0

.balign 8
d1: .double 0.0
d2: .double 0.0

.text

.global main /* entry point must be global */
.func main /* ’main’ is a function */
main: /* This is main */
   ldr r1, =return
   str lr, [r1]

   ldr r0, =msg1
   bl printf

   ldr r0, =scan_pattern @ r0 <- &scan_pattern
   ldr r1, =d1
   bl scanf

   ldr r0, =msg2
   bl printf

   ldr r0, =scan_pattern @ r0 <- &scan_pattern
   ldr r1, =d2
   bl scanf

   ldr r1, =d1
   vldmia.f64 r1, {d0-d1}


   vadd.f64 d0, d0, d1

   // printf only accepts doubles
   // double is passed on r2 & r3
   ldr r0, =msg3
   vmov r2,r3,d0
   bl printf
   
   ldr r1, =return
   ldr lr, [r1]
   bx lr

/* External */
.global printf
.global scanf

the makefile to assemble and link the program:

# Makefile
all: first fploop
fploop: fploop.o
	gcc -g -o $@ $+
fploop.o : fploop.s
	as -g -mfpu=vfpv2 -o $@ $<
first: first.o
	gcc -g -o $@ $+
first.o : first.s
	as -g -mfpu=vfpv2 -o $@ $<
clean:
	rm -vf first fploop *.o

Testing it out:

image

Amazing! lol

I also experimented with seeing how long some of the VFP instructions take. In this program I run a tight loop 1 billion times on a VFP instruction:

.data
msg1: .asciz "Looping: (%d) times...\n"
msg2: .asciz "\nResult =: %3.1e\n"
scan_pattern : .asciz "%lf"

.balign 4
return: .word 0
loopcount: .word 1000000000


.balign 8
d1: .double 1.0
d2: .double 1.0

.text

.global main /* entry point must be global */
.func main /* ’main’ is a function */
main: /* This is main */
   ldr r1, =return
   str lr, [r1]

   ldr r0, =msg1
   ldr r1, =loopcount
   ldr r1, [r1]
   bl printf

   ldr r1, =d1
   vldmia.f64 r1, {d0-d1}

   ldr r1, =loopcount
   ldr r1, [r1]
loop:
//   vadd.f64 d2, d0, d1
//   vadd.f64 d0, d0, d1
//   vmla.f64 d2, d0, d1
   subs r1, r1, #1
   bne loop

   ldr r0, =msg2
   vmov r2,r3,d0
   mov r1,#0
   bl printf
   
   ldr r1, =return
   ldr lr, [r1]
   bx lr

/* External */
.global printf
.global scanf

Just the loop itself, the sub and conditional branch run at the full system clock rate. Pretty snazzy!

image

(d1 never got modified so it remained at its initial value of 1.)

Adding one VFP instruction at a time and reassembling and running results in the following:

vadd.f64 d2, d0, d1 => 2s

vadd.f64 d0, d0, d1 => 4s

vmla.f64 d2, d1, d0 => 4s

That is a lot of processing power for a $15 development board.

  • Sign in to reply
  • Cancel
Parents
  • scottiebabe
    scottiebabe over 3 years ago

    I also got to try out gdbgui:

    image

    Which could be handy, as being a web frontend you could load the page on a phone or a tablet.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • javagoza
    javagoza over 3 years ago in reply to scottiebabe

    Programming in assembler from a phone. I can't stop laughing, it reminded me of the hexadecimal keyboard I used on the first computer I built from a kit.

    I gave mine to a friend years ago, here you can see photos of what it looked like.

    http://retro.hansotten.nl/6502-sbc/elektuur-junior/

    Thanks for the links.

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • Cancel
  • scottiebabe
    scottiebabe over 3 years ago in reply to javagoza

    I can't even imagine how tedious that must have been. lol There is a retired MS developer doing a few videos on the KIM-1 that you may find interesting:

    https://www.youtube.com/watch?v=X2UPNiv-h_U 

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • ralphjy
    ralphjy over 3 years ago in reply to scottiebabe

    Almost makes me want to break out my Kim-1...

    Haven’t used it in decades.  Might not even power up.  I probably would have a hard time finding my edge connectors that were wired for power and interface and I’m sure the cassette tapes are toast even if my cassette player might still work.

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • Cancel
  • scottiebabe
    scottiebabe over 3 years ago in reply to ralphjy

    That is extra fancy! That is too cool, you've held onto your Kim-1! I can only imagine how many hours the video presenter is spending behind the scenes to demonstrate what appears to be so simple.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • Jan Cumps
    Jan Cumps over 3 years ago in reply to ralphjy

    We had a similar one at school. But it came in a plastic fold-open box (opens like a book) with a PCB in each lid. And flex cable between the two halves.
    Same principle: processor, a few 7-segment LEDS and a little hex keyboard.

    I haven't been able to find a photo online.

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • Cancel
  • ralphjy
    ralphjy over 3 years ago in reply to Jan Cumps

    I had a black plastic shell for mine also but it was just the single pcb and it just snapped together.  I also built a video character interface to a monochrome CRT that I mentioned in this post: RP2040-HDMI-Display

    I'll try to get a picture of my board, although I think most of the accessories that I built are missing...

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • Cancel
  • ralphjy
    ralphjy over 3 years ago in reply to scottiebabe

    It took a couple of tries, but I did find it.  Sill in the original MOS Technology box...

    image

    image

    I am definitely not going to start playing with it, because as you say it could be a huge time sink and I'm working on other things.  I'm not even going to unscrew it from the case Smile.

    • Cancel
    • Vote Up +5 Vote Down
    • Sign in to reply
    • Cancel
  • dougw
    dougw over 3 years ago in reply to ralphjy

    My first electronics (summer) job involved building many of the early SBCs of the era - including Kim 1, Sym 1 and RCA 1802 COSMAC. There was a Motorola 6800, Signetics 2650 and Intel 8080 in the group as well , but they didn't have names and I don't remember the part numbers. There was no Apple 1 in the mix. 

    I considered it to be a very lucky job to have landed.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • dougw
    dougw over 3 years ago in reply to ralphjy

    My first electronics (summer) job involved building many of the early SBCs of the era - including Kim 1, Sym 1 and RCA 1802 COSMAC. There was a Motorola 6800, Signetics 2650 and Intel 8080 in the group as well , but they didn't have names and I don't remember the part numbers. There was no Apple 1 in the mix. 

    I considered it to be a very lucky job to have landed.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
Children
  • ralphjy
    ralphjy over 3 years ago in reply to dougw

    Yep, I remember all of those.  I still have my Apple 2+, but haven't used that in over 20 years.  I mainly used 6502s and some 8080s in things that I built in that timeframe.  At work we were mostly using 6800s and 8080s.  I'm a bit older than you, so I was lucky to have the opportunity use the 8008 in college.

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • Cancel
  • javagoza
    javagoza over 3 years ago in reply to ralphjy

    I didn't have the money to buy an Apple II so we started a computer hobbyist club and bought an Apple IIe with a Z80 expansion card that also supported the CP/M operating system. A few years later I started working for Apple in my country as a VAX VMS specialist to integrate Apple networks with DEC VAX VMS systems. That experience did not last long, I did not see myself selling hardware. First sentence that they burned into me: "The client is someone who has our money and we have to get it back" Really?

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube