Computer Organization
In this course the topics of digital logic and assembly language programming were covered. Also taught was simple hardware layout and construction as well as memory organization and cache principles.
TA Work
During my fourth year of university I decided to make some extra money by being a teaching assistant for a computer science course. Why not get paid well to do something you love, right? Just as luck would have it I was offered a position as a teaching assistant for this course, COMP 2003. My first time through the course I had learnt assembly language for 16-bit Intel x86, which at the time was somewhat outdated. This time through however, the material had been updated to IA-32 which had me pleasantly surprised.
Many of the assignments had to deal with simulation of data being fed through to the program from a serial transmission line. Usually this meant that as the data was being read in, it would have to be masked appropriately to get the correct value which would later be manipulated by the program. Even though bit masking is not all that complicated, I found a few neat tricks I’ll share below.
Assignment #2
The purpose of the second assignment was to receive four input characters from the user which would then be used to set certain bits in a byte, representing sets of lights in a house which would have been turned on by the command.
To simulate the transmission, the 4 bytes containing the input characters were packed into an array of 32 bytes, with each byte in the array containing the value of a single bit from the input data. The approach used is shown below.
After moving a single byte of input to the BL register, we get each bit by shifting the BX register to the left. This causes the value of our most significant bit to be placed directly into the register BH. From here, we can simply copy the contents of BH into the array which will be our simulated input.
pack_input: mov BL, AL ; move first char into bl pack_input_inner: shl BX, 1 ; ith bit of char now in bh mov [ESI+EDX], BYTE BH ; move val of bit to array xor BH, BH ; clear bh for next iteration
The same process was followed in reverse to rebuild the transmission into its proper bytes. A byte would be moved to a high byte of a 16 bit register, and shifted right by one bit. After this was done eight times, we have our constructed byte available in the low byte of the same register.
Assignment #3
The third assignment was to write an assembly language program which would receive a stream of bits following a predefined message protocol, and then strip out important information from the message to display to the user. The protocol defined a message which contained a crude internet protocol address, the message itself, a checksum, and various other control characters.
To read in the data a supplied macro was used to load each bit from the simulated input stream. Following this the character read in was first tested for its value, and if it was a ’1′ we increment the byte being constructed. After testing the value, we simply execute a left bit shift. This works since we are both reading and constructing the byte in a left-to-right fashion, while also setting the current bit being looked at to its corresponding value. Note that in the code below ECX is being used as a counter to make sure we only decode one byte at a time (which is related to the macro buffer size).
getByte: shl AL, 1 GetCh BL ; use a macro to get input cmp BL, '0' ; test for value je isZero inc AL ; inc. current bit if we see a '1' isZero: dec ECX jnz getByte
Assignment #4
Both times through this course the fourth assignment was used to teach mixed-mode programming. Although I haven’t used this too much it stands out as one of the more interesting sections of the course in my opinion.
The program itself is made to execute an easy data conversion (ie/ hex integer to decimal) so that more emphasis can be placed on the process of parameter passing using the stack. Control flows from the main C function to assembly, where a separate C function is called to do some work. After this, control then returns to the assembly function which continues on to do some work before returning to the main C function.
Categories
- bmx (1)
- hardware (1)
- software (2)
- uncategorized (1)
Articles
- January 2012 (2)
- November 2011 (3)