Allocating Memory
In Lab 7, you allocated memory for a truth table using the .byte assembly directive. For this lab, you will need to allocate other blocks of memory.
The online manual describes several assembly directives for allocating space. The information is summarized below:
| Directive | Description |
| .byte X | Allocates 1 byte equal to the value X |
| .short X | Allocates 2 bytes (16 bits) equal to the value X |
| .long X | Allocates 4 bytes equal to the value X |
| .ascii X | Allocates an ASCII string |
| .fill X | Creates a block of X bytes will all of the values initialized to zero |
| .asciz X | Allocates an ASCII string with a zero-termination |
For example, to declare a global variable nVal in your code, insert the following directives and labels, preferably at the end of your code:
.data
; Not required, but if used, only one is needed
; preceding blocks of memory being allocated
nVal:
.byte 0
This code allocates 1 byte of memory with the initial value of zero. To access the block of memory, you would need to follow the standard conventions used in Lab 7.
lis r5, nVal@h
ori r5, r5, nVal@l
li r6,
200 ; r6 <- the value 200
stb r6, 0(r5) ; Write to
nVal, r6 -> nVal
This code segment sets the byte for nVal equal to the value 200. You can of course read/write the data as necessary.
Allocating a block of memory
For this lab, it will be necessary to allocate a block of data for a buffer. You may want to use a block of 128, 256 or more bytes of memory for the buffers. To allocate a block of 256 bytes, use the following code:
QT_Buffer:
.fill 256
To access the memory, you could use the following code:
lis r10, QT_Buffer@h
ori r10, r10, QT_BUffer@l
lbz r15,
5(r10)
; r15 <- QT_Buffer[5]