* * 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 * *----------------------------------------------------------- * * Starting address of program * in main mem. * This command tells the * assembler to calculate * addresses starting from * the specified hex address. *----------------------------------------------------------- 0x00000000: 0x8C01000E init: LW r1 r0 loop_size * r1 = loop_size value * r1 will be our counter * 0x00000001: 0x8C02000D LW r2 r0 strt_adrs * r2 = strt_adrs value * r2 will be out ptr * 0x00000002: 0x2C030000 ADDI r3 r0 0 * r3=0. * r3 will be our accumulator * *----------------------------------------------------------- * First test if cntr<=0. If so, exit. * 0x00000003: 0x78240000 SLEI r4 r1 0 * test if cntr<=0 if so r4=1 * else r4=0 0x00000004: 0x14800005 BNEZ r4 end_prog * if r4!=0 go to endlp *----------------------------------------------------------- sum_lp: 0x00000005: 0x8C450000 LW r5 r2 0 * * r5=*ptr (r5=*r2) 0x00000006: 0x00651823 ADD r3 r3 r5 * r3=r3+r5 0x00000007: 0x2C420001 ADDI r2 r2 1 * ptr++ (r2++) 0x00000008: 0x2C21FFFF ADDI r1 r1 -1 * cntr-- (r1--) 0x00000009: 0x1420FFFB BNEZ r1 sum_lp * if cntr!=0 goto fill *----------------------------------------------------------- * * end_prog: 0x0000000A: 0x2C04000F ADDI r4 r0 result * r4 = result adrs value 0x0000000B: 0xAC830000 SW r3 r4 0 * *r4=r3 * =store sum into result *----------------------------------------------------------- * endlp: 0x0000000C: 0x1000FFFF BEQZ r0 endlp * * *----------------------------------------------------------- * * Here the data of this program starts * strt_adrs: 0x0000000D: 0x00000012 DC 0x00000012 * First memory address * to be summed loop_size: 0x0000000E: 0x00000005 DC 0x00000005 * loop size = 5 * 0x0000000F: result: DS 0x00000001 * result *----------------------------------------------------------- * put the next data block * starting from 0x00000012 0x00000012: 0x00000001 DC 0x00000001 0x00000013: 0x00000020 DC 0x00000020 0x00000014: 0x00000300 DC 0x00000300 0x00000015: 0x00004000 DC 0x00004000 0x00000016: 0x00050000 DC 0x00050000 *-----------------------------------------------------------