CPSC 359 Study Guide - Midterm Guide: Java Bytecode, Byte Addressing, Java Class File

528 views12 pages
Microarchitecture Design & Operation
javac: Java compiler. Compiles HL Java to Bytecode
Bytecode = Java Assembly (JAS) Language
JVM: Java Virtual Machine. An interpreter of Java Bytecode
.java --> javac --> .class --> java --> hardware
IJVM: subset of JVM that deals with integers. No floating point instructions. All integer JAS
opcodes are 1-byte long. Simpler to deal with.
Stacks: JVM is an operand stack machine. Used to push local procedure variables. Local Variable
Frame: data structure between LV and SP.
Stacks are used to push operands during the computation of arithmetic expressions.
Constant Pool: Constants, strings & pointers to other areas of memory. Does not change after
loading (cannot be written by IJVM program). CPP contains the address of the first word.
Local Variable Frame/ Operand Stack: Allocated to variables stored for the lifetime of a
procedure. At the beginning of the frame: parameters, then local variables, then operand stack.
LV points to the start of LVF. TOS = word at top of stack.
Method Area: Program text. PC points to the instruction to be fetched next.
Offsets: CPP, LV & SP: word pointers. Offset is a word. LV+1: second word in LFV. SP: word on
TOS. SP-1: next to top word.
PC: byte address. Offset is a byte. PC+1 next byte to be fetched.
IVOKEVIRTUAL disp: Invokes another method. disp(16 bit) = position in constant pool that
contains the address in method area where method starts.
Cannot call methods except in the same object. (No Object Orientation)
Caller: Pushes OBJREF being called onto stack.(Not needed for IJVM). Pushes method
parameters. First paramer is param 1
First 4 bytes of a method: First 2 are the number of parameters, including OBJREF (param0)
Second 2: Size of local variable area.
CODE:
int j = 100
int s = 0
for (int i = 0; i < j; i++)
s += i
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows pages 1-3 of the document.
Unlock all 12 pages and 3 million more documents.

Already have an account? Log in
IJVM:
.main
.var
i
j
s
.end-var
start:
BIPUSH 0x64 // 100
ISTORE j
BIPUSH 0x0
DUP
ISTORE s
ISTORE i
check:
ILOAD i
ILOAD j
ISUB // i - j
IFLT for_body // i < j
GOTO end
for_body:
// s += i
ILOAD i
ILOAD s
IADD
ISTORE s
// i ++
ILOAD i
BIPUSH 0x1
IADD
ISTORE i
GOTO check
end:
.end-main
Defining Methods in JAS
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows pages 1-3 of the document.
Unlock all 12 pages and 3 million more documents.

Already have an account? Log in
.method methodName
.var
variables
.end-var
body
...
IRETURN
.end-method
Calling Methods in JAS
LCD_W OBJREF
INVOKEVIRTUAL methodName
Before .main, you need:
.constant
OBJREF 0x40
.end-constant
Calling Methods in JAS with Parameters
LCD_W OBJREF
ILOAD param1
ILOAD param2
INVOKEVIRTUAL methodName
PRINTING ALL ASCII VALUES
.constant
one 1
start 32
stop 126
.end-constant
.main
LDC_W start
next: DUP
OUT // output the current character
DUP
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows pages 1-3 of the document.
Unlock all 12 pages and 3 million more documents.

Already have an account? Log in

Get access

Grade+
$10 USD/m
Billed $120 USD annually
Homework Help
Class Notes
Textbook Notes
40 Verified Answers
Study Guides
1 Booster Class