element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • More
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • More
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • More
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • More
  • 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
Raspberry Pi
  • Products
  • More
Raspberry Pi
Forum My First Assembly Program on a PI Zero2W
  • Blog
  • Forum
  • Documents
  • Events
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Raspberry Pi requires membership for participation - click to join
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 19 replies
  • Subscribers 125 subscribers
  • Views 489 views
  • Users 0 members are here
Related

My First Assembly Program on a PI Zero2W

scottiebabe
scottiebabe 11 days ago

I recently stumbled across this great ebook:

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:

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!

(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.

  • Reply
  • Cancel
  • Cancel

Top Replies

  • ralphjy
    ralphjy 11 days ago in reply to scottiebabe +5

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

    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…

  • scottiebabe
    scottiebabe 10 days ago +5

    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.

    In 4s, the one logical core ends up complete 8 billion instructions…

  • ralphjy
    ralphjy 11 days ago in reply to scottiebabe +4

    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…

  • scottiebabe
    scottiebabe 11 days ago

    I also got to try out gdbgui:

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

    • Cancel
    • Up +2 Down
    • Reply
    • Cancel
  • javagoza
    javagoza 11 days 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
    • Up +3 Down
    • Reply
    • Cancel
  • scottiebabe
    scottiebabe 11 days 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
    • Up +2 Down
    • Reply
    • Cancel
  • ralphjy
    ralphjy 11 days 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
    • Up +4 Down
    • Reply
    • Cancel
  • scottiebabe
    scottiebabe 11 days 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
    • Up +2 Down
    • Reply
    • Cancel
  • Jan Cumps
    Jan Cumps 11 days 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
    • Up +3 Down
    • Reply
    • Cancel
  • ralphjy
    ralphjy 11 days 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
    • Up +3 Down
    • Reply
    • Cancel
  • ralphjy
    ralphjy 11 days ago in reply to scottiebabe

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

    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
    • Up +5 Down
    • Reply
    • Cancel
  • dougw
    dougw 11 days 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
    • Up +2 Down
    • Reply
    • Cancel
  • scottiebabe
    scottiebabe 11 days ago in reply to ralphjy

    That is extraordinary! Your Kim-1 is in immaculate condition and still has the original box! Thanks for sharing a photo :) my first SBC is not nearly as fancy (or quite as old) a pic12 on a pickit1 lol I should try to find it too and post a photo.

    • Cancel
    • Up +2 Down
    • Reply
    • Cancel
>
Element14

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 © 2022 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

  • Facebook
  • Twitter
  • linkedin
  • YouTube