Some Pentium assembly language using gcc... these generally show how some high-level language constructs are accomplished in assembly code:
| Test case | Description |
| array1 | define and use a global array |
| array2 | define and use an un-initialized global array |
| array3 | define and use a local array variable |
| array4 | loop through the values in an array |
| for1 | demonstrate a for loop |
| func1 | demonstrate a function call |
| hello1 | "Hello world" example |
| if1 | demonstrate an if statement |
| if2 | demonstrate an if-then-else statement |
| local1 | define and use local variables |
| scanf1 | demonstrate use of scanf() function |
| switch1 | demonstrate a switch statement |
| while1 | demonstrate a while loop |
For each test case above, here are links to the C code, gcc-generated assembly code, and my clean-up version of the assembly code.
| Test case | C code | gcc -S assembly | My modified assembly |
| array1 | array1.c | array1.s | array1_mod.s |
| array2 | array2.c | array2.s | array2_mod.s |
| array3 | array3.c | array3.s | array3_mod.s |
| array4 | array4.c | array4.s | array4_mod.s |
| for1 | for1.c | for1.s | for1_mod.s |
| func1 | func1.c | func1.s | func1_mod.s |
| hello1 | hello1.c | hello1.s | hello1_mod.s |
| if1 | if1.c | if1.s | if1_mod.s |
| if2 | if2.c | if2.s | if2_mod.s |
| local1 | local1.c | local1.s | local1_mod.s |
| scanf1 | scanf.c | scanf.s | scanf_mod.s |
| switch1 | switch1.c | switch1.s | switch1_mod.s |
| while1 | while1.c | while1.s | while1_mod.s |
One more "example." Here's a file I use as a starting point or template when creating assembly code files. This may keep you from making silly mistakes and also keeps a nice common style across files.
Copy this template file to your local folder and modify it for your purposes.
Please note: all these examples and the template reside in the Common Area of our class k: drive.