codegenx86
Class X86Support

java.lang.Object
  extended by codegenx86.X86Support

public class X86Support
extends java.lang.Object

x86 assembly support create an object from this class for use in generating x86 code


Field Summary
 int SYSCALL_BRK
          brk syscall
 int SYSCALL_EXIT
          Exit syscall
 int SYSCALL_FILE_CLOSE
          File close syscall
 int SYSCALL_FILE_OPEN
          File open syscall
 int SYSCALL_FILE_READ
          File read syscall
 int SYSCALL_FILE_WRITE
          File write syscall
 int SYSCALL_GET_TIME
          Get time syscall
 
Constructor Summary
X86Support(java.io.PrintStream out)
          X86Support constructor
 
Method Summary
 void genAdd(java.lang.String srcReg, java.lang.String destReg)
          Generate an add instruction
 void genAlign()
          Generate word alignment directive
 void genAnd(java.lang.String srcReg, java.lang.String destReg)
          Generate an and instruction
 void genAscii(java.lang.String ascii)
          Generate an ASCII string (terminates with zero byte and aligns)
 void genByte(java.lang.String dataByte)
          Generate a data byte
 void genComment(java.lang.String text)
          Generate a comment
 void genCondBeq(java.lang.String reg1, java.lang.String reg2, java.lang.String label)
          Generate a conditional branch branches if first operand is equal to second operand
 void genCondBgeq(java.lang.String reg1, java.lang.String reg2, java.lang.String label)
          Generate a conditional branch branches if first operand is greater than or equal to second operand
 void genCondBgt(java.lang.String reg1, java.lang.String reg2, java.lang.String label)
          Generate a conditional branch branches if first operand is greater than second operand
 void genCondBleq(java.lang.String reg1, java.lang.String reg2, java.lang.String label)
          Generate a conditional branch branches if first operand is less than second operand
 void genCondBlt(java.lang.String reg1, java.lang.String reg2, java.lang.String label)
          Generate a conditional branch branches if first operand is less than or equal to second operand
 void genCondBne(java.lang.String reg1, java.lang.String reg2, java.lang.String label)
          Generate a conditional branch branches if first operand is not equal to second operand
 void genDataStart()
          Generate the code to start the data section
 void genDirCall(java.lang.String label)
          Generate a direct call
 void genDiv(java.lang.String srcReg)
          Generate a divide instruction (note: puts quotient in %eax and remainder in %edx)
 void genGlobal(java.lang.String label)
          Generate a global
 void genInDirCall(java.lang.String reg)
          Generate an indirect call
 void genLabel(java.lang.String label)
          Generate a reference label
 void genLoadByte()
          Generate a load byte instruction Note: uses the address in %esi (this register), increments %esi, and automatically puts result in the accumulator (%eax)
 void genMod(java.lang.String srcReg)
          Generate a modulus instruction (note: puts quotient in %eax and remainder in %edx)
 void genMove(int imm, java.lang.String destReg)
          Generate a move instruction - loads an immediate into a register
 void genMove(int offset, java.lang.String baseReg, java.lang.String destReg)
          Generate a move instruction - loads a register value to memory
 void genMove(java.lang.String srcReg, int offset, java.lang.String baseReg)
          Generate a move instruction - stores a register value to memory
 void genMove(java.lang.String src, java.lang.String destReg)
          Generate a move instruction - a register-to-register move or a load address depending on whether the source parameter is a register or a label
 void genMul(java.lang.String srcReg)
          Generate a multiply instruction (note: puts result in %eax, also overwrites %edx with 0)
 void genNeg(java.lang.String reg)
          Generate a negation instruction
 void genNot(java.lang.String reg)
          Generate a not instruction
 void genOr(java.lang.String srcReg, java.lang.String destReg)
          Generate an or instruction
 void genPop(java.lang.String reg)
          Generate a pop instruction
 void genPush(java.lang.String reg)
          Generate a push instruction
 void genRetn()
          Generate a return
 void genShiftLeft(java.lang.String destReg)
          Generate a shift left instruction (note: shift amount is taken from %ecx)
 void genShiftRight(java.lang.String destReg)
          Generate a shift right instruction (note: shift amount is taken from %ecx)
 void genSpace(int n)
          Generate a data segment of size n
 void genStoreByte()
          Generate a store word instruction Note: uses the address in %edi, increments %edi, and takes the value from the accumulator (%eax)
 void genSub(java.lang.String srcReg, java.lang.String destReg)
          Generate a subtraction instruction
 void genSyscall(int syscallId)
          Generate a system call
 void genTextStart()
          Generate the code to start the data section
 void genUncondBr(java.lang.String label)
          Generate an unconditional branch
 void genWord(java.lang.String dataWord)
          Generate a data word
 void genXor(java.lang.String srcReg, java.lang.String destReg)
          Generate an xor instruction
 java.lang.String getAccReg()
          Get the accumulator register (note: this is eax)
 java.lang.String getEAXReg()
          Get the eax register (note: this is the accumulator)
 java.lang.String getEBXReg()
          Get the ebx register
 java.lang.String getECXReg()
          Get the ecx register
 java.lang.String getEDIReg()
          Get the edi register
 java.lang.String getEDXReg()
          Get the edx register
 java.lang.String getESIReg()
          Get the esi register (note: this is 'this' register)
 java.lang.String getFPReg()
          Get the frame pointer register
 java.lang.String getLabel()
          Get a unique label for use with control flow
 int getNextAvailStackOffset()
          Get next available stack offset
 java.lang.String getSPReg()
          Get the stack pointer register
 java.lang.String getThisReg()
          Get the register that holds 'this' pointer (note: this is esi)
 int getWordSize()
          Get the word size
 void setNextAvailStackOffset(int offset)
          Set next available stack offset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SYSCALL_EXIT

public final int SYSCALL_EXIT
Exit syscall

See Also:
Constant Field Values

SYSCALL_FILE_OPEN

public final int SYSCALL_FILE_OPEN
File open syscall

See Also:
Constant Field Values

SYSCALL_FILE_CLOSE

public final int SYSCALL_FILE_CLOSE
File close syscall

See Also:
Constant Field Values

SYSCALL_FILE_READ

public final int SYSCALL_FILE_READ
File read syscall

See Also:
Constant Field Values

SYSCALL_FILE_WRITE

public final int SYSCALL_FILE_WRITE
File write syscall

See Also:
Constant Field Values

SYSCALL_GET_TIME

public final int SYSCALL_GET_TIME
Get time syscall

See Also:
Constant Field Values

SYSCALL_BRK

public final int SYSCALL_BRK
brk syscall

See Also:
Constant Field Values
Constructor Detail

X86Support

public X86Support(java.io.PrintStream out)
X86Support constructor

Parameters:
out - print stream
Method Detail

getNextAvailStackOffset

public int getNextAvailStackOffset()
Get next available stack offset

Returns:
next available stack offset

setNextAvailStackOffset

public void setNextAvailStackOffset(int offset)
Set next available stack offset

Parameters:
offset - new available stack offset

getSPReg

public java.lang.String getSPReg()
Get the stack pointer register

Returns:
register name

getFPReg

public java.lang.String getFPReg()
Get the frame pointer register

Returns:
register name

getThisReg

public java.lang.String getThisReg()
Get the register that holds 'this' pointer (note: this is esi)

Returns:
register name

getAccReg

public java.lang.String getAccReg()
Get the accumulator register (note: this is eax)

Returns:
register name

getEAXReg

public java.lang.String getEAXReg()
Get the eax register (note: this is the accumulator)

Returns:
register name

getEBXReg

public java.lang.String getEBXReg()
Get the ebx register

Returns:
register name

getECXReg

public java.lang.String getECXReg()
Get the ecx register

Returns:
register name

getEDXReg

public java.lang.String getEDXReg()
Get the edx register

Returns:
register name

getEDIReg

public java.lang.String getEDIReg()
Get the edi register

Returns:
register name

getESIReg

public java.lang.String getESIReg()
Get the esi register (note: this is 'this' register)

Returns:
register name

genComment

public void genComment(java.lang.String text)
Generate a comment

Parameters:
text - text to put in comment

genDataStart

public void genDataStart()
Generate the code to start the data section


genTextStart

public void genTextStart()
Generate the code to start the data section


genGlobal

public void genGlobal(java.lang.String label)
Generate a global

Parameters:
label - label to make global

genWord

public void genWord(java.lang.String dataWord)
Generate a data word

Parameters:
dataWord - word string

genByte

public void genByte(java.lang.String dataByte)
Generate a data byte

Parameters:
dataByte - byte string

genSpace

public void genSpace(int n)
Generate a data segment of size n

Parameters:
n - size of data segment

genAscii

public void genAscii(java.lang.String ascii)
Generate an ASCII string (terminates with zero byte and aligns)

Parameters:
ascii - ASCII string

genAlign

public void genAlign()
Generate word alignment directive


getLabel

public java.lang.String getLabel()
Get a unique label for use with control flow

Returns:
label string

getWordSize

public int getWordSize()
Get the word size

Returns:
word size

genMove

public void genMove(java.lang.String src,
                    java.lang.String destReg)
Generate a move instruction - a register-to-register move or a load address depending on whether the source parameter is a register or a label

Parameters:
src - string containing the source (register or label)
destReg - string containing the destination register

genMove

public void genMove(int imm,
                    java.lang.String destReg)
Generate a move instruction - loads an immediate into a register

Parameters:
imm - immediate to load into destination register
destReg - string containing the destination register

genMove

public void genMove(int offset,
                    java.lang.String baseReg,
                    java.lang.String destReg)
Generate a move instruction - loads a register value to memory

Parameters:
offset - integer offset (must be a multiple of the word size)
baseReg - string containing the base register
destReg - string containing the destination register

genMove

public void genMove(java.lang.String srcReg,
                    int offset,
                    java.lang.String baseReg)
Generate a move instruction - stores a register value to memory

Parameters:
srcReg - string containing the source register
offset - integer offset (must be a multiple of the word size)
baseReg - string containing the base register

genLoadByte

public void genLoadByte()
Generate a load byte instruction Note: uses the address in %esi (this register), increments %esi, and automatically puts result in the accumulator (%eax)


genStoreByte

public void genStoreByte()
Generate a store word instruction Note: uses the address in %edi, increments %edi, and takes the value from the accumulator (%eax)


genPush

public void genPush(java.lang.String reg)
Generate a push instruction

Parameters:
reg - string containing the register to push onto the stack

genPop

public void genPop(java.lang.String reg)
Generate a pop instruction

Parameters:
reg - string containing the register to hold popped stack value

genAdd

public void genAdd(java.lang.String srcReg,
                   java.lang.String destReg)
Generate an add instruction

Parameters:
srcReg - string containing the source register
destReg - string containing the destination register

genSub

public void genSub(java.lang.String srcReg,
                   java.lang.String destReg)
Generate a subtraction instruction

Parameters:
srcReg - string containing the source register
destReg - string containing the destination register

genMul

public void genMul(java.lang.String srcReg)
Generate a multiply instruction (note: puts result in %eax, also overwrites %edx with 0)

Parameters:
srcReg - string containing the source register

genDiv

public void genDiv(java.lang.String srcReg)
Generate a divide instruction (note: puts quotient in %eax and remainder in %edx)

Parameters:
srcReg - string containing the source register

genMod

public void genMod(java.lang.String srcReg)
Generate a modulus instruction (note: puts quotient in %eax and remainder in %edx)

Parameters:
srcReg - string containing the source register

genAnd

public void genAnd(java.lang.String srcReg,
                   java.lang.String destReg)
Generate an and instruction

Parameters:
srcReg - string containing the source register
destReg - string containing the destination register

genOr

public void genOr(java.lang.String srcReg,
                  java.lang.String destReg)
Generate an or instruction

Parameters:
srcReg - string containing the source register
destReg - string containing the destination register

genXor

public void genXor(java.lang.String srcReg,
                   java.lang.String destReg)
Generate an xor instruction

Parameters:
srcReg - string containing the source register
destReg - string containing the destination register

genShiftLeft

public void genShiftLeft(java.lang.String destReg)
Generate a shift left instruction (note: shift amount is taken from %ecx)

Parameters:
destReg - string containing the destination register

genShiftRight

public void genShiftRight(java.lang.String destReg)
Generate a shift right instruction (note: shift amount is taken from %ecx)

Parameters:
destReg - string containing the destination register

genNeg

public void genNeg(java.lang.String reg)
Generate a negation instruction

Parameters:
reg - string containing the source and destination register

genNot

public void genNot(java.lang.String reg)
Generate a not instruction

Parameters:
reg - string containing the source and destination register

genLabel

public void genLabel(java.lang.String label)
Generate a reference label

Parameters:
label - label string

genDirCall

public void genDirCall(java.lang.String label)
Generate a direct call

Parameters:
label - label string

genInDirCall

public void genInDirCall(java.lang.String reg)
Generate an indirect call

Parameters:
reg - register containing callee address

genRetn

public void genRetn()
Generate a return


genUncondBr

public void genUncondBr(java.lang.String label)
Generate an unconditional branch

Parameters:
label - label string

genCondBeq

public void genCondBeq(java.lang.String reg1,
                       java.lang.String reg2,
                       java.lang.String label)
Generate a conditional branch branches if first operand is equal to second operand

Parameters:
reg1 - first register to compare
reg2 - second register to compare
label - label to branch to

genCondBne

public void genCondBne(java.lang.String reg1,
                       java.lang.String reg2,
                       java.lang.String label)
Generate a conditional branch branches if first operand is not equal to second operand

Parameters:
reg1 - first register to compare
reg2 - second register to compare
label - label to branch to

genCondBlt

public void genCondBlt(java.lang.String reg1,
                       java.lang.String reg2,
                       java.lang.String label)
Generate a conditional branch branches if first operand is less than or equal to second operand

Parameters:
reg1 - first register to compare
reg2 - second register to compare
label - label to branch to

genCondBleq

public void genCondBleq(java.lang.String reg1,
                        java.lang.String reg2,
                        java.lang.String label)
Generate a conditional branch branches if first operand is less than second operand

Parameters:
reg1 - first register to compare
reg2 - second register to compare
label - label to branch to

genCondBgt

public void genCondBgt(java.lang.String reg1,
                       java.lang.String reg2,
                       java.lang.String label)
Generate a conditional branch branches if first operand is greater than second operand

Parameters:
reg1 - first register to compare
reg2 - second register to compare
label - label to branch to

genCondBgeq

public void genCondBgeq(java.lang.String reg1,
                        java.lang.String reg2,
                        java.lang.String label)
Generate a conditional branch branches if first operand is greater than or equal to second operand

Parameters:
reg1 - first register to compare
reg2 - second register to compare
label - label to branch to

genSyscall

public void genSyscall(int syscallId)
Generate a system call

Parameters:
syscallId - the system call number