lmc assembly making programming friendlier. machine code issues have to remember numeric opcodes...

10
LMC Assembly Making Programming Friendlier

Upload: willis-hodge

Post on 12-Jan-2016

214 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: LMC Assembly Making Programming Friendlier. Machine Code Issues Have to remember numeric opcodes Have to think about physical memory locations – What

LMC AssemblyMaking Programming Friendlier

Page 2: LMC Assembly Making Programming Friendlier. Machine Code Issues Have to remember numeric opcodes Have to think about physical memory locations – What

Machine Code Issues

• Have to remember numeric opcodes• Have to think about physical memory

locations– What if I need to add 6 lines

of code to this program?

Page 3: LMC Assembly Making Programming Friendlier. Machine Code Issues Have to remember numeric opcodes Have to think about physical memory locations – What

Assembly

• Assembly Code : human readable machine code

Page 4: LMC Assembly Making Programming Friendlier. Machine Code Issues Have to remember numeric opcodes Have to think about physical memory locations – What

Assembly

• Little Man Computer Assembly:

AssemblyMachine

code0 INP 9011 STA FIRST 3072 LDA TEN 5063 ADD FIRST 1074 OUT 9025 HLT 0006 TEN DAT 10 0107 FIRST DAT 0 000

Assembly Machine code Instruction HLT 000 end (halt) ADD 1xx add SUB 2xx subtract STA 3xx store STore Accumulator valueLDA 5xx load LoaD into AccumulatorBRA 6xx branch always BRanch AlwaysBRZ 7xx branch if 0 BRanch if ZeroBRP 8xx branch if >= 0 BRanch if zero or PositiveINP 901 input OUT 902 output DAT data location Used to specify a memory location

Page 5: LMC Assembly Making Programming Friendlier. Machine Code Issues Have to remember numeric opcodes Have to think about physical memory locations – What

DAT

• DAT Value: "this location is data"– Value is placed into memory

5 HLT 0006 TEN DAT 10 0107 FIRST DAT 0 000

Page 6: LMC Assembly Making Programming Friendlier. Machine Code Issues Have to remember numeric opcodes Have to think about physical memory locations – What

Identifier

• Identifier : Name for a memory location– Can come before any instruction

IDENTIFIER INSTRUCTION …

5 HLT 0006 TEN DAT 10 0107 FIRST DAT 0 000

Page 7: LMC Assembly Making Programming Friendlier. Machine Code Issues Have to remember numeric opcodes Have to think about physical memory locations – What

No XX

• Assembly can use names for memory locations

Assembly Machine code0 INP 9011 STA FIRST 3072 LDA TEN 5063 ADD FIRST 1074 OUT 9025 HLT 0006 TEN DAT 10 0107 FIRST DAT 0 000

Page 8: LMC Assembly Making Programming Friendlier. Machine Code Issues Have to remember numeric opcodes Have to think about physical memory locations – What

Names And Branch

• Use as target of branch:– #1

This is called LOOPSTARTWe add one to accumulator

– #3Branch to the instructionnamed LOOPSTART

Assembly

0 LDA ZERO

1 LOOPSTART ADD ONE

2 OUT

3 BRA LOOPSTART

4 HLT

5 ZERO DAT 0

6 ONE DAT 1

Page 9: LMC Assembly Making Programming Friendlier. Machine Code Issues Have to remember numeric opcodes Have to think about physical memory locations – What

Named Locations

• Named locations not affected by adding/removing code

Ex: Add EXTRA lines– Assembly fine– Machine version broken

Assembly Machine code0 INP 9011 STA FIRST 3072 LDA TEN 5063 ADD FIRST 1074 EXTRA EXTRA5 EXTRA EXTRA6 OUT 9027 HLT 0008 TEN DAT 10 0109 FIRST DAT 0 000

Page 10: LMC Assembly Making Programming Friendlier. Machine Code Issues Have to remember numeric opcodes Have to think about physical memory locations – What

Assembler

• An Assembler converts assembly to machine code:

http://faculty.chemeketa.edu/ascholer/cs160/Files/LMC/LMCAssembler.html