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 4176 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
  • ralphjy
    ralphjy over 3 years ago in reply to scottiebabe

    Thanks.  Funny that you mentioned Pics.  I didn't get into them until later in life and I'll admit to not knowing where any of that stuff is now, but I do have the box (LOL) from my PICSTART-16B which was my first entry into Pic programming,  I got it when it first came out in 1993.  I don't recall what I programmed initially, but I think it was the 16C84.  And I still have an Embedded Control Handbook from 1992 - you could probably guess the date from the pictures on the cover... I wish I had kept my old phones and pagers Stuck out tongue.

    image

    image

    image

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • 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
  • scottiebabe
    scottiebabe over 3 years ago in reply to ralphjy

    LOL my pickit1 isn't quite that old... the USB connector places it a few years later...

    image

    I also found the gumstix eval kit I bought in 2010:

    image image

    I never did buy a beagle board though. I remember them being advertised in digikey catalogs, perhaps I should find one used on ebay to add to the collection lol

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

    The cortex-A53 on the zero2w is also a super-scaling bad-****. Here I add a few more integer instructions that end up running in parallel.

    image

    In 4s, the one logical core ends up complete 8 billion instructions, while only being clocked at 1 GHz. 

    image

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

    The pickit1 is much fancier than the picstart-16b - doesn't have the big ZIF socket, though Grinning.   Do you still have software that works with it?

    Not familiar with gumstix stuff.  What are the two antennas for?

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

    My current MPLabX IDE doesn't even list the pickit1 :( . I have downloaded an old version of MPLab before they moved to the now eclipse based MPLabX. I still have to see if it works lol

    The 2 antennas were for wifi/bluetooth, this diagram shows the general idea:

    image

    It was based around the TI omap3 series applications processor, for the time it was pretty impressive, at least I thought so lol I still remember trying to build a yocto linux image from source it took over day if everything went smoothly ( I didn't have a solid state hard drive at the time).  https://www.gumstix.com/community/support/hardware/overo/    

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

    The pickit1 still works! I used the archived version of MPLab 8.92 on microchip.com it recognized the pickit Smiley

    image

    image

    How can you not love the application notes on bitbanging I2C,UART,SPI ...

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

    Fabulous!   Great stuff.  Does bring back memories...

    • Cancel
    • Vote Up +1 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