============================= Assembly: malloc() and free() [TOC] ============================= The program loader of the ULM initializes _%2_ with the number of byte loaded. For convenience it also sets _%3_ with the value of _%2_ rounded up to the next multiple of 8. This can be used for an aligned _break pointer_, i.e. an address right after the data and BSS segment. For this quiz we will use this break pointer a simple _malloc()_ and _free()_ implementation: - Function ~_start~ first copied the value of _%3_ into a global variable _break_. Then it initializes the stack pointer and calls _main()_. - Function _malloc_ expects one parameter for the block size that should be allocated. It makes a copy of the current break pointer in a local variable _oldBreak_. It then increments the global variable _break_ by _size_ and also rounds up the result to the next multiple of eight. - Function _free_ would return and not release any memory. We therefore actually do not implement it in the exercise and also do not call it. In the quiz you can test the implementation of _malloc()_ with a program that generates a list from user input. Quiz 17: Dynamic Single Linked List =================================== The following C program is kind of a blue print for what you should implement in assembly: :import: session16/list/dyn_list.c [fold] The program reads in characters from _stdin_ until it gets a newline. For each character before the newline it creates a new list node that can store a single character. New nodes are prepended to a list that initially is empty. Before the program terminates it prints the characters stored in the list by first calling function _printList()_ then function _printListReverse()_. Both print function expect as parameter a pointer to the first list node: - If the list is not empty function _printList()_ prints the character stored in the first node. It then proceed analogously with the next list node. - If the list is not empty function _printListReverse()_ first calls _printListReverse()_ recursively by passing a pointer to the next node, i.e. characters in successor nodes will be printed first. When the recursive function call returns it prints the character stored in its node. Here a test run with input "abc123": ---- SHELL (path=session16/list) ----------------------------------------------- gcc -o dyn_list dyn_list.c echo "abc123" | ./dyn_list -------------------------------------------------------------------------------- The following skeleton can be used for a port to assembly: :import: session16/list/dyn_list_quiz16.s [fold] You just have tom complete the blanks in function _main()_, _malloc()_ and _printListReverse()_. ---- CODE (type=sh) ----------------------- submit hpc quiz17 isa.txt dyn_list.s -------------------------------------------