12/8/2015\course\cpeg323-07fs\topic2b-323.ppt1 topic 2b high-level languages and system software...
TRANSCRIPT
04/22/23 \course\cpeg323-07Fs\Topic2b-323.ppt 1
Topic 2b High-Level languages and
System Software(Languages)
Introduction to Computer Systems Engineering
(CPEG 323)
04/22/23 \course\cpeg323-07Fs\Topic2b-323.ppt 2
Reading List
• Slides: Topic2b
• K & R : C Programming Language
• JAVA in a Nutshell
Processors
Programs Written in High Level LanguagesHow Processors see the high level languages?The role of toolchainsConnections between ISA and high-level languagesConnections between ISA and Operating Systems
04/22/23 \course\cpeg323-07Fs\Topic2b-323.ppt 3
High Programming Languages
PortabilityAbstraction Penalty
Languages Categories Imperative (C) Functional (LISP) Logic (PROLOG) Object Oriented (Java) Scripting (Python)
04/22/23 \course\cpeg323-07Fs\Topic2b-323.ppt 4
Tim
elin
e o
f Pro
gra
mm
ing
Languages
04/22/23 \course\cpeg323-07Fs\Topic2b-323.ppt 5
Courtesy of Wikipedia. Original Author: Maximilian Dörrbecker
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
04/22/23 \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
04/22/23 \course\cpeg323-07Fs\Topic2b-323.ppt 7
C versus Java
C
ImperativeFunctionsLibraries are low levelManual Memory ManagementPointersLow Memory OverheadRelatively FastVariables initialize to garbage
Java
Object OrientedMethodsClass libraries of data structuresAutomatic Memory ManagementHigh Memory OverheadRelatively SlowVariables initialized to zero
04/22/23 \course\cpeg323-07Fs\Topic2b-323.ppt 8
C versus JavaHello, World in C Hello, World in Java
04/22/23 \course\cpeg323-07Fs\Topic2b-323.ppt 9
#include <stdio.h>
int main(int argc, char **argv)
{
/* This is a comment!!! */
printf("Hello, world!\n");
return 0;
}
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
C versus Java
04/22/23 \course\cpeg323-07Fs\Topic2b-323.ppt 10
C Code
Lexical AnalyzerSyntax
Analyzer
IR CG and Semantic Analyzer
CG
Optimizer
Symbol Table
Computer
Machine Code
Lexical AnalyzerSyntax
Analyzer
IR CG and Semantic Analyzer
Java Code
Java Byte Code (e.g. Java Source code .class files)
Java Virtual Machine
API Class filesJava
Platform
C Syntax
Very similar to Java but with a few differencesVariable Declarations must go at the beginning of the block (before they are used)A variable may be initialized in its declaration
04/22/23 \course\cpeg323-07Fs\Topic2b-323.ppt 11
Memory Storage for HLPL
Linear Storage of multi dimensional arrayRow Major order (C, C++, JAVA)
04/22/23 \course\cpeg323-07Fs\Topic2b-323.ppt 12
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)
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)
Memory
Memory Storage for HLPL
Column Major order (Fortran, MATLAB)
04/22/23 \course\cpeg323-07Fs\Topic2b-323.ppt 13
Memory
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)
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)
Assembly Language
Compiler Generates Assembly codeAssembly 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
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)
04/22/23 \course\cpeg323-07Fs\Topic2b-323.ppt 14
Load 32-bit Immediate
04/22/23 \course\cpeg323-07Fs\Topic2b-323.ppt 15
LUI R9, 0xAAAA
op 16-bit Imm
AAAAAAAA BBBBBBBB
op 16-bit ImmR9R9 R9
R9
ADDIU R9, R9, 0xBBBB
Load 32-bit Immediate
04/22/23 \course\cpeg323-07Fs\Topic2b-323.ppt 16
ADDI R9, R0, 0xAAAAop 16-bit Imm
AAAA
op 16-bit ImmR9
R9
R9
R9
SHORI R9,R9, 0xBBBB
BBBBAAAA
Shift 16 bits or
Assembly Language
Assembly language(cont.) Assembler directives
.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
04/22/23 \course\cpeg323-07Fs\Topic2b-323.ppt 17