* * Example of asm program * *----------------------------------------------------------- * This programs sums up all values inside the n memory * addresses starting from the address written in ``strt_adrs''. * n is written in ``loop_size'' address. The result should be * stored into the address specified by ``result''. * * ``strt_adrs'', ``loop_size'' and ``result'' are labels of * addresses in the memory. The data inside the first two must * be put there prior to runing the program * *----------------------------------------------------------- * pc = 0x00000000 * Starting address of program * in main mem. * This command tells the * assembler to calculate * addresses starting from * the specified hex address. *----------------------------------------------------------- init: lw r1 r0 loop_size * r1 = loop_size value * r1 will be our counter * lw r2 r0 strt_adrs * r2 = strt_adrs value * r2 will be out ptr * addi r3 r0 0 * r3=0. * r3 will be our accumulator * *----------------------------------------------------------- * First test if cntr<=0. If so, exit. * slei r4 r1 0 * test if cntr<=0 if so r4=1 * else r4=0 bnez r4 end_prog * if r4!=0 go to endlp *----------------------------------------------------------- sum_lp: * lw r5 r2 0 * r5=*ptr (r5=*r2) add r3 r3 r5 * r3=r3+r5 addi r2 r2 1 * ptr++ (r2++) addi r1 r1 -1 * cntr-- (r1--) bnez r1 sum_lp * if cntr!=0 goto fill *----------------------------------------------------------- * * end_prog: addi r4 r0 result * r4 = result adrs value sw r3 r4 0 * *r4=r3 * =store sum into result *----------------------------------------------------------- * endlp: beqz r0 endlp * * *----------------------------------------------------------- * * Here the data of this program starts * strt_adrs: dc 0x00000012 * First memory address * to be summed loop_size: dc 0x00000005 * loop size = 5 * result: ds 1 * 1 address for storing the * result *----------------------------------------------------------- pc = 0x00000012 * put the next data block * starting from 0x00000012 dc 0x00000001 dc 0x00000020 dc 0x00000300 dc 0x00004000 dc 0x00050000 *-----------------------------------------------------------