I am given this assignment:
This program is supposed to search an array of bytes for the value 0xf2. When it finds 0xf2, it should save its location (i.e. address) into the integer variable “f2Address”. If it does not find the value of 0xf2 in the array, it should put a value of 0x00 into the variable “f2Address”. This program has some bugs in it. Fix this program so that it does work properly.
The original code given was:
.label TABLE1_LOC_START
TABLE1 .byte 0xff,0xfe,0xfd,0xfc,0xfb,0xfa,0xf9,0xf8,0xf7,0xf6,0xf5,0xf4,0xf3,0xf2,0xf1,0xf0
TABLE1_ST .word TABLE1_LOC_START
RESET mov.w #0280h,SP
mov.w #WDTPW+WDTHOLD,&WDTCTL ; stop watchdog timer
mov &TABLE1_ST, R10
mov #0xf2, R11
mov #0x08, R12
again inc R10
cmp 0(R10), R11
je found
dec R12
jz again
found mov R10, &f2Address
endProgram jmp endProgram
In an attempt to solve this problem I changed the 'je' to 'jeq' and I added 'mainLoop' to the code. After my modifications I had this code:
.label TABLE1_LOC_START
TABLE1 .byte 0xff,0xfe,0xfd,0xfc,0xfb,0xfa,0xf9,0xf8,0xf7,0xf6,0xf5,0xf4,0xf3,0xf2,0xf1,0xf0
TABLE1_ST .word TABLE1_LOC_START
mainLoop mov &TABLE1_ST, R10
mov #0xf2, R11
mov #0x08, R12
again inc R10
cmp R10, R11
jeq found
dec R12
jnz again
found mov R10, &f2Address
endProgram jmp endProgram
When I step through it, R12 eventually decrements to zero. Once it does, it means that the value of 0xf2 wasn't found, so it should place a 0x00 in the 'f2Address'. But instead of placing a zero there, it simply keeps on moving through the instructions without changing/adding any values anywhere.
I am not quite sure what to do or where to go next from here. It is using CodeComposer on the MSP430.