Docsity

Programming Languages - Lecture Notes | BME 303, Lab Reports of Biology

Toggle sidebar
bg1
BME303 Intro. to Computing
Programming Languages
Programming
Languages
• Generally, programming
languages describe programs
Problem
Human
languages
describe
programs
at various levels of detail,
where the coarsest
classification distinguishes
hi h l l l ( C
Algorithms
Analytical thinker
Pro
g
rammer
–
hi
g
h
l
eve
l
l
anguages
(
e.g.,
C
,
C++, Fortran, Pascal, etc.)
– low level languages which are
much ā€œcloserā€ to the
underlying ISA
Language
Machine (ISA) Architecture
g
Compiler, Assembler
underlying
ISA
• Whatever the level, a program
written in that lan
g
ua
g
e must
Machine
(ISA)
Architecture
Micro-architecture
gg
be translated to a program in
machine language (ML) , i.e.,
its instructions are in the
com
uter’s ISA.
Circuits
Electrons
1
Devices
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31

Partial preview of the text

Download Programming Languages - Lecture Notes | BME 303 and more Lab Reports Biology in PDF only on Docsity!

BME303 Intro. to Computing

Programming LanguagesProgramming Languages

-^ Generally, programminglanguages describe programs

Problem

Human

languages describe programsat various levels of detail,where the coarsestclassification distinguisheshi h l

l l^

(^ C

Algorithms

Analytical thinkerProgrammer

-^ high level languages (e.g., C,C++, Fortran, Pascal, etc.)–^ low level languages which aremuch ā€œcloserā€ to theunderlying ISA

Language

Machine (ISA) Architecture

g Compiler, Assembler

underlying ISA

-^ Whatever the level, a programwritten in that language must

Machine (ISA) ArchitectureMicro-architecture

g^ g

be translated to a program inmachine language (ML) , i.e.,its instructions are in thecomputer’s ISA.

Circuits

Electrons

p

Devices

BME303 Intro. to Computing

Chapter 7: Assembly LanguageChapter 7: Assembly LanguageHigh-level^

Assembly

Machine

Compiler

Assembler

LanguageProgram

LanguageProgram

LanguageProgram

Compiler

Assembler

P^
☺^
P^
/^

C^ t^

Computer

Computer Programmer

☺^

Programmer

/^

Computer

-^ Instead of writing in machine code we can write our programs usinga more "friendlyā€œ programming language:a more "friendlyā€œ programming language:–^

Assembly language (now)– C++, MATLAB, LabVIEW (later)

-^ System software provides us with software tools to translateprograms into machine code:–^

AssemblerC^ il

-^ Compiler

BME303 Intro. to Computing

The Instruction MnemonicsThe Instruction Mnemonics• Mnemonic: A system to develop orMnemonic: A system to develop orimprove the memory.• Better term: Symbolic Name• Better term: Symbolic Name• ADD, AND, NOT, LD, LDI, LDR, LEA, ST,STI, STR, BR, TRAP, JMP, JSR/JSSR,RTI• Still have a one-to-one correspondence

p

with Machine Language Instructions

BME303 Intro. to Computing

We’ve seen mnemonics already:e

e see

e^ o

cs a eady

Address

Instruction

Comments

x30F^

1110 001 111111101LEA^

R^

+1^ PC= x30F7 R1^ ←^ PC

+1^ āˆ’^ 3 = x30F

x30F^

0001 010 001 1 01110ADD^

R2^ R

R2^ ←^ R1 + 14 = x

+1^ PC^5

30F

30F

x30F^

0011 010 111111011ST^

R2^ #-

+1 PCāˆ’^5

= x30F

āˆ’^ 5 = x30F

M[0x30F4]

←^ R

R2^ AND

x0000 = x

x30F^

0101 010 010 1 00000AND^

R2^ R

R2^ AND

x0000 = x

R2^ ←^^0

x30FA^

0001 010 010 1 00101ADD^

R2^ R

R2^ ←^ R2 + 5 = 5

BME303 Intro. to Computing

Labels and CommentsLabels and Comments

•^ Labels are symbolic names that identify memoryl^

ti^

f^ d t

li itl^

i^ th^

A^

bl

locations referred to explicitly in the AssemblyLanguage Program (APL), e.g., the locationcontainscontains– the target of a branch instruction– a value that is loaded or stored• The optional comments part of the instruction(begins with a leading semi colon) consists of(begins with a leading semi-colon) consists ofremarks that explain the instruction’s role in theprogram

p^ g

BME303 Intro. to Computing

Typical Assembly Program StructureTypical Assembly Program StructureLabel^

Opcode

Operands

; Comments

Label

Opcode

Operands

; Comments

.ORIG

0x

Load program at this address

...^

...^

Program is here

...^

...

LABEL

...

... ...^

... HALT

Stops the program

LABEL

...

...^

Data

...^

... .END^

End of program code

BME303 Intro. to ComputingAppendix AAppendix A

BME303 Intro. to Computing

Pseudo-Ops (Assembler Directives)Pseudo Ops (Assembler Directives)•^ These are directives that aid the LC-3 assembler intranslating an ALP to its corresponding MLP•^ The LC-3 assembler has

^5 such pseudo-ops:

  • .ORIGFILL– .FILL– .BLKW– .STRINGZ– .END• As with ordinary operations, pseudo-ops may have s^ t^

o d^ a y ope at o s, pseudo ops

ay^

a e

operands

BME303 Intro. to ComputingExample

p

; ;^ Program

to^ multiply

a^ number

by^ the

constant

.ORIG^

0x LD^

R1,^ SIX
LD^
R2,^ NUMBER
AND^
R3,^ R3,
#^

; Clear

R3.^ It

will ; contain

the^ product.

; The^ inner

loop ; AGAIN^

ADD^
R3,^ R3,
R
ADD^
R1,^ R1,
#-^

;^ R1^ keeps

track^

of

BRp^

AGAIN^

; the^ iteration.

HALT
; NUMBER^
.BLKW^
1 #^

;^ Number

to^ be^

multiplied

SIX^
.FILL^

0x ;

.END

BME303 Intro. to Computing.END

•^ Tells the assembler where the ALP endsTells the assembler where the ALP ends•^ Needed by the assembler in the process ofNeeded by the assembler in the process ofmaking the ALP to MLP translation•^ Do not confuse this with stopping the executionof the corresponding MLPo t e co

espo d

g

•^ Indeed

END does not exist at execution time

Indeed, .END does not exist at execution time

BME303 Intro. to ComputingBLKW.BLKW

•^ Directs the assembler to set aside a specified number of

ti l^

l^ ti

sequential

memory locations

•^ Example: NUMBER .BLKW 1 #67 says that one location(in the example, this location turns out to be 0x3057 inthe resulting Machine Language Program), should be setaside, where the label of this location is NUMBER and itis^ initialized

with

-^ Initialized to ā€œ0ā€ without specification –^ 67 will be treated as #67. x67 is treated as hex; –^ .BLKW 5 67 will create five locations, all initialized with #67.

•^ This pseudo-op is particularly useful when the actualvalues of certain MLP operands are not known prior toprogram execution

program execution

BME303 Intro. to ComputingExample

p

; ;^ Program

to^ multiply

a^ number

by^ the

constant

.ORIG^

0x LD^

R1,^ SIX
LD^
R2,^ NUMBER
AND^
R3,^ R3,
#^

; Clear

R3.^ It

will ; contain

the^ product.

; The^ inner

loop ; AGAIN^

ADD^
R3,^ R3,
R
ADD^
R1,^ R1,
#-^

;^ R1^ keeps

track^

of

BRp^

AGAIN^

; the^ iteration.

HALT
; NUMBER^
.BLKW^
1 #^

;^ Number

to^ be^

multiplied

SIX^
.FILL^

0x ;

.END

BME303 Intro. to ComputingExample

p

; ;^ Program

to^ multiply

a^ number

by^ the

constant

.ORIG^

0x LD^

R1,^ SIX
LD^
R2,^ NUMBER
AND^
R3,^ R3,
#^

; Clear

R3.^ It

will ; contain

the^ product.

; The^ inner

loop ; AGAIN^

ADD^
R3,^ R3,
R
ADD^
R1,^ R1,
#-^

;^ R1^ keeps

track^

of

BRp^

AGAIN^

; the^ iteration.

HALT
; NUMBER^
.BLKW^
1 #^

;^ Number

to^ be^

multiplied

SIX^
.FILL^

0x ;

.END

BME303 Intro. to ComputingSTRINGZ.STRINGZ

-^ Given a string of n characters in quotes (the operand), this pseudo-op directs theassembler to store the corresponding n zero-extended ASCII codes plus a sentinel inassembler to store the corresponding n zero extended ASCII codes plus a sentinel inthe next (n+1) consecutive memory locations•^ Example: .ORIG x

GB .STRINGZ ā€œUT BMEā€Address:

Value 0x3000:^

0x^

U

0x3001:^

0x^

T

0x3002:^

0x^

(space)

0x3003:^

0x^

B

0x3004:^

0x004D^

M

0x3005:^

0x^

E

0x3007:^

0x^

(sentinel)

What are the differences between .FILL, .BLKW and .STRINGZ?