Escolar Documentos
Profissional Documentos
Cultura Documentos
Homework 3
Write code for the following problems. Submit soft copies via SLATE.
• In each of the following you are supposed to write a function with the specified
parameters to perform the specified task.
• Make sure that all these functions preserve the register contents and empty the
stack from parameters after return.
1. Write a function called print_char which accepts a single word (16 bit) input in
parameter whose lower 8-bits contain the ASCII of the character to be printed
and higher 8-bits are zero, and a 16-bit offset value. The function should then
print the character whose ASCII has been provided by moving it to the specified
offset on the video memory, which starts at 0xB8000.
The following code snippet explains how to print the character ‘A’ at offset si. The
ASCII of ‘A’ is 0x41. You will have to move a whole word (16 bits) to the video
memory where the lower byte of the word is the ASCII and the higher byte is
fixed to 0x07; therefore to print ‘A’ you will move 0x0741 to the video memory.
What does it mean to switch the stack? The stack is defined by the SS and SP
registers, the former containing the segment base and the latter the offset of the top of
the stack. Changing the stack would mean that both SS and SP are loaded with new
values. However, while doing so, you must be careful that the function itself is using the
stack in push and ret instructions. It must remove all the preserved registers, the return
address and parameters from the older stack as all functions do. When it returns to the
caller the transition should be smooth, and the new stack should be in use.
7. Here’s another problem from your book. Make an array of 0x80 bytes and treat it
as one of 0x400 bits. Write a function myalloc that takes one argument, the
number of bits. It finds that many consecutive zero bits in the array, makes them
one, and returns in AX the index of the first bit. Write another function myfree that
takes two arguments, index of a bit in the array, and the number of bits. It makes
that many consecutive bits zero, whatever their previous values are, starting from
the index in the first argument.
THE END