Komphyler
HamidReza Kamkari 97110177
Mostafa Ojaghi 97105782
Yeganeh Gharedaghi 97106216
Input and Output: The following commands handle simple input and output of character.
Input x: Takes an Integer as an input and writes it inxOutput x: Outputs the value inx.
Assign value commands:
Assign x = y: Set the value ofxequal to the value ofyAssign x = a op b: This command calculatesa op band then writes the output in x.opcan have forms such as follows:+: Addaandb-: Subtractbfroma*: Multiplyaandb/: Calculateadivided byb%: Calculateamodb<: Ifais strictly less thanbthen the value1will be written intoxotherwise0<=: Ifais less than or equal tobthen the value1will be written intoxotherwise0>: Ifais strictly larger thanbthen the value1will be written intoxotherwise0>=: Ifais larger than or equal tobthen the value1will be written intoxotherwise0==: Ifaandbare equal then1will be written intoxotherwise0!=: Ifaandbare not equal then1will be written intoxotherwise0&&: Calculate logical and ofaandb(aandbshould be0or1)||: Calculate logical or ofaandb(aandbshould be0or1)
Assign x = not y:yshould be0or1and the calculated not is written intoxAssign x = - y: negateyand then write the negated value intox
Labels and goto:
label labelName:: defines a label to be able to jump to.goto labelName: A simple jump to label namedlabelName
Function call commands:
label functionName: param1 param2 param3 ...: This defines a label, if the label is a function the parametersparam1,param2, ... are the input arguments.Lcall functionName: Call the function that has a label namedfunctionNameLcall functionName -> r: Call the function that has a label namedfunctionNameand then return the value from that function inrPushparam x: This adds argumentxto the stack before function call.Popparams sz: Free the stackBeginfunc sz: Free the stack byszbytes, this is used to free space for each local variable that is used in the function. Caution: keep in mind if you have 3 variables in a function you should start the function withBeginfunc 12.Endfunc: ends the function.Endfunc var: returns the value that is stored invar
Exit command:
Exit: If this line is read then the program exits.
Global Variables: each program in TAC is written as follows:
Assign g1 = 0
Assign g2 = 0
Assign g3 = 0
.
.
.
Assign gk = 0
Lcall main
Exit
label main:
Beginfunc s
.
.
.
Endfunc
label func1: arg1 arg2 ...
Beginfunc s1
.
.
.
Endfunc ret1/nothing
label func2: arg1 arg2 ...
.
.
.
The variables g1, g2, ..., gk are all global variables and the function
main is the function that is being called. Other procedures such as func1, func2 ...
are all functions that may or may not return value. To call each of these functions an arbitrary amount of
Pushparam x may be needed if they have input arguments and then after each function call there should
be a Popparams sz.
Pointers: The following commands include memory access.
Store *(a + offset) = b: Store the value ofbin offset bytes afterain memory.Load a = *(b + offset): Load the value in addesb + offsetof memory
##TAC tests
Simple function call example:
Assign global1 = 10
Assign global2 = 20
Lcall main
Exit
label main:
Assign x = 0
Assign y = 1
Assign z = 2
Pushparam x
Pushparam y
Pushparam z
Lcall function -> r
Popparams 12
label function: z y x
Beginfunc 4
Assign s = x + y
Assign s = s - z
Assign s = s + global1
Endfunc s
Lcall main
Exit
Label main:
Beginfunc 64
Input s
Output s
Input a
Output a
Assign b = s / a
Assign b = - s
Output b
Pushparam b
Lcall f -> x
Popparams 4
Output x
Endfunc
Label f: c
Beginfunc 64
Output c
Lcall check
Endfunc c
Label check:
Beginfunc 64
Input y
Output y
Endfunc