Skip to content

Instantly share code, notes, and snippets.

@JoshTGreenwood
Created June 20, 2014 17:42
Show Gist options
  • Save JoshTGreenwood/27e81638428225e2bc0f to your computer and use it in GitHub Desktop.
Save JoshTGreenwood/27e81638428225e2bc0f to your computer and use it in GitHub Desktop.
Assembly Code to search for a value in memory
/*
* midterm.asm
*
* Created: 6/20/2014 11:41:46 AM
* Author: Josh
*/
.org 0x0
ldi r29,0x00
ldi r30,0x10
ldi r31,0xFF
start:
// sets PORTE data direction to read
sts PORTE_DIR, r29
// loads the contents of PORTE to r16
lds r16, PORTE_IN
// sets X pointer register to 0
clr XL
clr XH
search:
// load to r17 from X pointer register
ld r17,X+
// check to make sure it isn't comparing r17 with r16
cpi r17, 0x10 // 0x10 is the location of r16
breq search
// compare r16 and r17
cp r16,r17
// if equal, light led
breq lightLED
// if at end of memory, restart
rjmp start
// go back to search
rjmp search
lightLED:
// sets PORTF data direction to write
sts PORTF_DIR, r30
// loads the contents of PORTE to r16
sts PORTF_OUT, r31
// infinite loop
rjmp lightLED
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment