Skip to content

Register Machine Code Format

Jiang edited this page Mar 20, 2020 · 4 revisions

<Here goes a description of the register machine code format, similar to Section 5.1.5 of SICP JS>

This section is still work in progress.

Treatment of register assignment:

1. Assigning a value from one register to another.

Assigning a value from register 'register-name-from' to 'register-name-to':

assign(register-name-to, reg(register-name-from))

For example, if you assign contents from register D to register C:

assign("C", reg("D"))

2. Assigning a value from one register to another.

Assigns a constant value to 'register-name'. Constant value is predefined.

assign(register-name, constant(constant-value))

During the treatment of a self-evaluating expression, we can also treat the expression as a constant value. Examples include:

Assignment of numeric values:

assign("A", constant(100))

Assignment of booleans:

assign("B", constant(true))
assign("C", constant(false))

Some noteworthy tips:

  • "register-name" seen in round brackets are just the actual register names in strings.

3. New instructions:

Even though SICP Instruction Summary 5.1.5 is already listed some instructions, we will remention it here as some instrcution APIs are not consistent.

3.1 Perfrom

Perform an operation:

perform(list(op(operation_name), inputs...))

3.2 Test

Test an operation:

test(list(op(operation_name), inputs...))

3.3 Branch

make a branch with a label:

branch(label(label_name))

3.4 Go_to

Go to corresponding label_name value:

go_to(label(label_name))

Go to corredponding register value:

go_to(reg(register_name))

3.5 save

Save the register value into stack:

save(register_name)

3.6 restore

Restore the value from stack to register:

restore(register_name)

3.7 vector_ref

Get the Nth element of the vector:

vector_ref(vector,n) 

3.8 vector_set

Set the Nth element of the vector with a value:

vector_set(vector, n, value)

Clone this wiki locally