NU32v2: Digital I/O Assembly Code

From Mech
Revision as of 20:19, 24 January 2011 by Lynch (talk | contribs) (New page: Let's say we called our code digio.c. When we compile it, we find an "object code" file digio.o somewhere. I can "disassemble" this object code to see an assembly language version of the...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Let's say we called our code digio.c. When we compile it, we find an "object code" file digio.o somewhere. I can "disassemble" this object code to see an assembly language version of the code. (You can also do this directly in the MPLAB IDE.) When we look at our disassembled code, we see a lot of stuff, including the block of code below. I added the comments beginning with //, since we don't know assembly language.

 354:  afc00010  sw     zero,16(s8)         // set i to zero

// start loop

 358:  8fc30010  lw     v1,16(s8)           // load i (from memory location 16(s8)) into register v1
 35c:  3c020098  lui    v0,0x98             // load 0x98 into upper 16 bits of v0
 360:  3442967f  ori    v0,v0,0x967f        // load 0x967f into lower 16, to give v0 = 9,999,999 in base 10
 364:  0043102a  slt    v0,v0,v1            // if v0 < v1, "sets" v0 (makes it nonzero)
 368:  1440ffe4  bnez   v0,2fc <main+0x2fc> // if v0 is nonzero (i.e., 10 M <= i), exit "for" loop
 36c:  00000000  nop                        // no operation 
 370:  8fc20010  lw     v0,16(s8)           // load i into v0
 374:  24420001  addiu  v0,v0,1             // (unsigned integer) add 1 to v0
 378:  afc20010  sw     v0,16(s8)           // store v0 back to i
 37c:  1000fff6  b      358 <main+0x358>    // go back to start of loop, instruction 358
 380:  00000000  nop                        // no operation


If you're interested to learn more about the assembly instruction set, you can start with http://en.wikipedia.org/wiki/MIPS_architecture, but we won't go into assembly in more detail.