Computer Architecture Lab/WS2007/Project -1 Lab4/AssemblerSyntax
< Computer Architecture Lab < WS2007 < Project -1 Lab4
Assembler syntax
Arithmetic functions
ADD("1","0","1E"); /* Add Random Number (contained in reserved Register $1E) with 0 (contained always in reserved Register $0) and store the result in $1 */
ADDU("1","3","2"); /* Adds unsigned values contained in $3 with unsigned value in $2 and stores the result in $1 */
SUB("3","1","2"); /* Substract $1 by $2 and store the result in $3 */
SUBU("1","3","2"); /* Substracts unsigned values contained in $3 with unsigned value in $2 and stores the result in $1 */
Logical functions:
AND("1","3","2"); /* $1 = $3 and $2 */
OR("1","3","2"); /* $1 = $3 or $2 */
XOR("1","3","2"); /* $1 = $3 xor $2 */
Shift functions:
SLL("2","5","1"); /* Shift the value contained in $5 left by 1 and store the result in $2 */
SLLV("2","5","1"); /* Shift the value contained in $5 left by value of $1 and store the result in $2 */
SRA("1","4","3"); /* Shift the value contained in $4 arithmetical right by 3 and store the result in $1 */
SRL("A","3","1"); /* Shift the value contained in $3 right by value of $1 and store the result in $A */
SRLV("A","5","1"); /* Shift the value contained in $5 left by 1 and store the result in $A */
(Un)Conditional functions:
BZS(LABEL); /* Branch if ZeroFlag is set, jump to LABEL */
BZC(LABEL); /* Branch if ZeroFlag is clear, jump to LABEL */
BNS(LABEL); /* Branch if NegativeFlag is set, jump to LABEL */
BNC(LABEL); /* Branch if NegativeFlag is clear, jump to LABEL */
BOS(LABEL); /* Branch if OverflowFlag is set, jump to LABEL */
BOC(LABEL); /* Branch if OverflowFlag is clear, jump to LABEL */
BOR(LABEL); /* Branch if RandomFlag is set, jump to LABEL */
BR(LABEL); /* jump to LABEL */
JR("3"); /* Jump to address contained in Register $3 */
Load and Store functions:
LLI("2","1"); /* Load value 1 to Register $2 */
LW("3","2"); /* Load value contained in Register $2 to Register $3 */
SW("3","2"); /* Store value contained in Register $2 to Register $3 */
NOOP:
NOOP(); /* do nothing */
RAMENTER: Writes a String into the RAM
RAMENTER ("4","7","11","Hello World. ",&pc);
/*
"$1 ... Addressregister, $2 ... Length register, $3 ... Increment Register
Arguments:
$1 ... Destination Address Register Number
$2 ... Buffer Length Register: Gets the number of stored characters
$3 ... Address Step Register: defines the address distance between two stored characters in RAM
$4 ... String
&pc .. (decoration)
*/
CALL Function
CALL (Label) /* Jump to Function "Label" */
RETURN from CALL
RETURN
Simple UART output
UART_SEND_STRING("Hello World",&pc); /* writes "Hello World" to the Terminal */
Debug output
DEBUG_SEND("1",&pc); /* Writes "Content of reg 0x01 is: " and the hex-value of the value contained in $1 */
Load a 32-bit Value:
LOAD_BIG_NUMBER("1","11","12345678",&pc); /* Load the whole 32-Bit hex-value into $1 with the temporary help of $11 */
Code Samples
Substraction example:
LLI("1",6); /* Load to Value 6 to Register $1 */
LLI("2",5); /* Load to Value 5 to Register $2 */
SUB("3","1","2"); /* Substract $1 by $2 and store the result in $3 */
Add 2 numbers and check if there is an overflow:
LABEL(START) /* Define Label START */
ADD("1","3","4"); /* ADD $3 with $4 and store the result in $1 */
BOS(OVERFLOWLABEL); /* if OverflowFlag is set jump to OVERFLOWLABEL */
BR(START); /* jump to START */
LABEL(OVERFLOWLABEL)/* define Label OVERFLOWLABEL */
UART_SEND_STRING("Warning: Overflow after ADD Operation!",&pc); /* Send warning to UART */
for further program samples go to Code Samples