Pentium Labs

Lab 0

This lab is easy. The goal is to simply make sure your compiler is working and that you are properly using the asm directive. See the lecture Inline Assembly for information on downloading and installing GCC (the GNU C compiler). The instructions used in the demo2.c program are the same ones you will need here (specifically mov, push, pop).

Replace the C implementation of the function tripleSwap() with an asm block in the program bigSwapper.c. Don't forget to test.

Lab 1 (CANCELLED)

Butcher's Algorithm is an amusing algorithm for determining the month and day of Easter given the year.

Replace the implementation of the calcEaster function in butcher.c with an asm block.

Lab 2

The algorithm for determining if a given year will be, is, or was a leap year is peculiar.

Replace the implementation of the setIsLeap function in leap.c with an asm block. You don't need to be faithful to the implementation.

Hint

The div and idiv instructions compute remainders. If X is a DWORD PTR (i.e., a 4 byte immediate, register, variable, or memory location), then the instructions:

div X

idiv X

Do this:

eax = edx:eax / X
edx = edx:eax % X

Recall edx:eax is the 64 bit int with low 32 bits stored in eax. (Probably for this assignment you can assume the high 32 bits in edx are all zeros.)

Lab 3

The dec2bin.c program perpetually prompts the user for an integer input, then displays the binary representation of that number:

enter an int -> 42
00000000000000000000000000101010
again?(y/n) y
enter an int -> -2
11111111111111111111111111111110
again?(y/n) y
enter an int -> 32000
00000000000000000111110100000000
again?(y/n) n
bye

Having trouble with jumping from the asm block below the call to printf back to the asm block above the call to printf? My guess is that the call to printf is clobbering the registers. Here's what finally worked for me. I stored the loop counter in a global variable called count. At the top of the loop I load count into a register, ecx for example, compare the register with 32, if it's smaller, I do my shift, then increment ecx and store it back into the global count before leaving the asm block to call printf.

Lab 4

Replace the functions choose, fact, and sum in math.c.

Note: Since we didn't cover call/return I simplified this problem.

Horstmann's Labs