Computer Architecture What Does It Mean??

Download Report

Transcript Computer Architecture What Does It Mean??

Topic 2b
High-Level languages and
System Software
(Languages)
Introduction to Computer
Systems Engineering
(CPEG 323)
7/17/2015
\course\cpeg323-07Fs\Topic2b-323.ppt
1
Reading List
• Slides: Topic2b
• K & R : C Programming
Language
• JAVA in a Nutshell
7/17/2015
\course\cpeg323-07Fs\Topic2b-323.ppt
2
Processors
Programs  Written in High Level Languages
How Processors see the high level languages?
The role of toolchains
Connections between ISA and high-level
languages
Connections between ISA and Operating
Systems
7/17/2015
\course\cpeg323-07Fs\Topic2b-323.ppt
3
High Programming Languages
Portability
Abstraction

Penalty
Languages Categories





7/17/2015
Imperative (C)
Functional (LISP)
Logic (PROLOG)
Object Oriented (Java)
Scripting (Python)
\course\cpeg323-07Fs\Topic2b-323.ppt
4
Timeline of Programming
Languages
7/17/2015
Courtesy of Wikipedia.
Original Author:
Maximilian Dörrbecker
\course\cpeg323-07Fs\Topic2b-323.ppt
5
C versus Java
C

K&R
 Initial implementation of C
 1978
 Weakly type checking for arguments and implicit integer
return type.

ANSI C / ISO C (C89 and C90)
 De facto standard
 Function prototypes, void pointers, international
character sets, preprocessor enhancements (e.g. ##
concatenation), prototypes, etc
7/17/2015
\course\cpeg323-07Fs\Topic2b-323.ppt
6
C versus Java
C

C99
Extension to several compilers
 Inline functions, new data types, variable length arrays (included in the GCC compiler), variadic
macros, etc

Java

“Get the power and flexibility of C++, but in a smaller, simpler and safer
language”
 Not implicit pointers
 Implicit Garbage Collection
 Control statements  Only controlled by primitive booleans
 Encapsulation is strictly enforced
 Concurrency Control
 Widening Cohercion only
 Applet versus standalone versus servlet versus Javaserver page versus swing
applications
7/17/2015
\course\cpeg323-07Fs\Topic2b-323.ppt
7
C versus Java
C
Java
Imperative
Functions
Libraries are low level
Manual Memory Management
Pointers
Low Memory Overhead
Relatively Fast
Variables initialize to garbage
7/17/2015
Object Oriented
Methods
Class libraries of data
structures
Automatic Memory
Management
High Memory Overhead
Relatively Slow
Variables initialized to zero
\course\cpeg323-07Fs\Topic2b-323.ppt
8
C versus Java
Hello, World in C
Hello, World in Java
#include <stdio.h>
public class HelloWorld {
public static void main(String[] args) {
int main(int argc, char **argv)
System.out.println("Hello, world!");
{
}
/* This is a comment!!! */
printf("Hello, world!\n");
}
return 0;
}
7/17/2015
\course\cpeg323-07Fs\Topic2b-323.ppt
9
C versus Java
Symbol
Table
C Code
Java Code
Lexical Analyzer
Lexical Analyzer
Syntax Analyzer
Syntax Analyzer
IR CG and
Semantic
Analyzer
IR CG and
Semantic
Analyzer
Optimizer
CG
Java Byte Code (e.g. Java
Source code .class files)
Machine Code
Computer
7/17/2015
Java
Platform
\course\cpeg323-07Fs\Topic2b-323.ppt
Java Virtual
Machine
API Class files
10
C Syntax
Very similar to Java but with a few
differences
Variable Declarations must go at the
beginning of the block (before they are
used)
A variable may be initialized in its
declaration
7/17/2015
\course\cpeg323-07Fs\Topic2b-323.ppt
11
Memory Storage for HLPL
Linear Storage of multi dimensional array
Row Major order (C, C++, JAVA)
int A[4][5] | int[][] A = new int[4][5];
A(1,1) A(1,2) A(1,3) A(1,4) A(1,5)
A(2,1) A(2,2) A(2,3) A(2,4) A(2,5)
A(3,1) A(3,2) A(3,3) A(3,4) A(3,5)
A(4,1) A(4,2) A(4,3) A(4,4) A(4,5)
7/17/2015
\course\cpeg323-07Fs\Topic2b-323.ppt
Memory
A(1,1)
A(1,2)
A(1,3)
A(1,4)
A(1,5)
A(2,1)
A(2,2)
A(2,3)
A(2,4)
A(2,5)
A(3,1)
A(3,2)
A(3,3)
A(3,4)
A(3,5)
A(4,1)
A(4,2)
A(4,3)
A(4,4)
A(4,5)
12
Memory Storage for HLPL
Column Major order (Fortran, MATLAB)
REAL A(4,5)
A(1,1) A(1,2) A(1,3) A(1,4) A(1,5)
A(2,1) A(2,2) A(2,3) A(2,4) A(2,5)
A(3,1) A(3,2) A(3,3) A(3,4) A(3,5)
A(4,1) A(4,2) A(4,3) A(4,4) A(4,5)
7/17/2015
\course\cpeg323-07Fs\Topic2b-323.ppt
Memory
A(1,1)
A(2,1)
A(3,1)
A(4,1)
A(1,2)
A(2,2)
A(3,2)
A(4,2)
A(1,3)
A(2,3)
A(3,3)
A(4,3)
A(1,4)
A(2,4)
A(3,4)
A(4,4)
A(1,5)
A(2,5)
A(3,5)
A(4,5)
13
Assembly Language
Compiler  Generates Assembly code
Assembly language

Pseudo Instructions
 li RX, Imm  Load Immediate to register

Translates to a pair of instructions (addiu / lui or addiu /
shori) if the immediate is greater than 16 bits
 la RX, VAR  Load address of “VAR” into register



7/17/2015
Translates according to the area in which VAR resides
Global Area: one instruction  addi RX, GP, OFFSET
Another Area: Two Instructions  lui RX, HI16(VAR);
addiu RX, RX, LOW16(VAR)
\course\cpeg323-07Fs\Topic2b-323.ppt
14
Load 32-bit Immediate
LUI
op
R9,
0xAAAA
R9
16-bit Imm
R9
7/17/2015
AAAA
ADDIU
op
R9, R9,
R9 R9
0xBBBB
16-bit Imm
BBBB
\course\cpeg323-07Fs\Topic2b-323.ppt
15
Load 32-bit Immediate
ADDI R9, R0, 0xAAAA
op
R9
R9
16-bit Imm
AAAA
SHORI R9,R9, 0xBBBB
op
16-bit Imm
R9 R9
Shift 16 bits
AAAA
7/17/2015
or
BBBB
\course\cpeg323-07Fs\Topic2b-323.ppt
16
Assembly Language
Assembly language(cont.)

Assembler directives











7/17/2015
.file – source file name
.text – start a text section
.align – alignment requirement
.data – data section
.rdata – read-only data section
.globl – an external name
.ent – entry of a function
.frame – information about the function frame
.mask – integer registers used in this function
.fmask – floating point registers used in this function
.ascii – define a string of characters
\course\cpeg323-07Fs\Topic2b-323.ppt
17