Память

Материал из Compilers Wiki
Версия от 16:56, 16 марта 2018; Admin (обсуждение | вклад) (Новая страница: «<strong>Инструкции сохранения.</strong> stored -- (d,m) # store + d (double) stores -- (s,m) # store + s (single) storel -- (l,m) # store…»)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Инструкции сохранения.

stored -- (d,m) # store + d (double)
stores -- (s,m) # store + s (single)
storel -- (l,m) # store + l (long)
storew -- (w,m) # store + w (word)
storeh -- (w,m) # store + h (half word)
storeb -- (w,m) # store + b (byte)

Существуют инструкции сохранения значения любого базового типа и любого расширенного типа. Поскольку h (half word) и b (byte) не являются первым классом в промежуточном языке, storeh и storeb принимают слово в качестве аргумента. Только первые 16 или 8 бит этого слова будут сохранены в памяти по адресу, указанному во втором аргументе.

Store instructions exist to store a value of any base type and any extended type. Since halfwords and bytes are not first class in the IL, storeh and storeb take a word as argument. Only the first 16 or 8 bits of this word will be stored in memory at the address specified in the second argument.

Инструкции загрузки.

loadd -- d(m) # load + d (double)
loads -- s(m) # load + s (single)
loadl -- l(m) # load + l (long)
loadsw, loaduw -- I(mm) # load + signed + w (word), load + unsigned + w (word)
loadsh, loaduh -- I(mm) # load + signed + h (half word), load + unsigned + h (half word)
loadsb, loadub -- I(mm) # load + signed + b (byte), load + unsigned + b (byte)

Для типов, меньшей размерности, чем l (long), доступны два варианта команды загрузки: один подпишет растягивает загруженное значение, а другое - нулевое. Обратите внимание, что все нагрузки, меньшие, чем длинные, могут загружаться либо длинным, либо одним словом.

For types smaller than long, two variants of the load instruction are available: one will sign extend the loaded value, while the other will zero extend it. Note that all loads smaller than long can load to either a long or a word.

Две команды loadsw и loaduw имеют тот же эффект, когда они используются для определения временного слова. Команда loadw является, скорее, синтаксическим сахаром для loadsw, чтобы указать, что используемый механизм расширения должен быть беззнаковым.

The two instructions loadsw and loaduw have the same effect when they are used to define a word temporary. A loadw instruction is provided as syntactic sugar for loadsw to make explicit that the extension mechanism used is irrelevant.


Размещение стека.

alloc4 -- m(l)
alloc8 -- m(l)
alloc16 -- m(l)

Эти инструкции выделяют область памяти в стеке. Номер, заканчивающийся именем команды, - это выравнивание, требуемое для выделенного слота. QBE гарантирует, что возвращенный адрес будет кратен значению этого выравнивания.

These instructions allocate a chunk of memory on the stack. The number ending the instruction name is the alignment required for the allocated slot. QBE will make sure that the returned address is a multiple of that alignment value.

Инструкции по распределению стека используются, например, при компиляции локальных переменных Cи, так как их можно получить по адресу. При компиляции Fortran, временные объекты могут использоваться напрямую, потому что недопустимо брать адрес переменной.

Stack allocation instructions are used, for example, when compiling the C local variables, because their address can be taken. When compiling Fortran, temporaries can be used directly instead, because it is illegal to take the address of a variable.

Ниже приведен пример использования некоторых инструкций памяти. Указатели имеют размерность l (long).

The following example makes use some of the memory instructions. Pointers are stored in long temporaries.
Пример.
%A0 =l alloc4 8      # stack allocate an array A of 2 words
%A1 =l add %A0, 4
storew 43,  %A0      # A[0] <- 43
storew 255, %A1      # A[1] <- 255
%v1 =w loadw  %A0    # %v1 <- A[0] as word
%v2 =w loadsb %A1    # %v2 <- A[1] as signed byte
%v3 =w add %v1, %v2  # %v3 is 42 here



Источник: c9x.me