Skip to content

Instantly share code, notes, and snippets.

@thomasbrus
Created December 19, 2011 16:07
Show Gist options
  • Save thomasbrus/1497795 to your computer and use it in GitHub Desktop.
Save thomasbrus/1497795 to your computer and use it in GitHub Desktop.
Count positive numbers
! This program determines the number of positive values in an array
!
! Register usage: %r1 - Index of array
! %r2 - Current value
! %r3 - Positive numbers counter
.begin
.org 2048
a_start .equ 3000
ld [address], %r1
ld [counter], %r3
loop: ld %r1, %r2 ! Load element of array at current index
addcc %r1, 4, %r1 ! Move address to next element
addcc %r2, %r2, %r0 ! Add r2 to itself
be done ! Exit if zero
bneg loop ! Loop before increasing the counter
inc %r3 ! Increase counter by one
ba loop
done: nop
nop
halt
counter: 0
address: a_start
.org a_start
a: 25, 10, 3, -4, 7, 8, 0
.end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment