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?