Tutorial Lab 1 S2010
Tutorial Lab 1 S2010
Lab Tutorial 1
Hand Assembling
1
Lab 1 Tutorial Outline
Objectives of Lab 1
Program Operation and Loading
3
Objectives of Lab 1
Use common assembler directives
e.g. equ, org, dc
4
Program Operation
5
I/O Subroutines
Out-Character
Store parameter D0 on the stack
Output the register D1 (in ASCII)
Restore D0 from the stack
In-Character
Store parameter D0 on the stack
Capture the input into D1 (in ASCII)
Select the first byte
Display the character
Restore D0 from the stack 6
Modify the Program
lea BUFFER,A1 ;point to start of buffer
bsr.w in_string ;read string and
bsr.w out_crlf ;go to next line
Hand assemble
movea.l #BUFFER+1024,A2 ;set up another buffer for result
Buffer + 1024
1 A2
B
8
Program Loading
9
OPCODES.TXT
mm 10210000
5468
6973
2070
726f
6772
616d
2077
696c
6c20
7072
696e
7420
6f75
7420
6120
7374
7269
6e67
2069
6e20
7468
6520 10
…etc
Hand Assembling of “Move”
Move.L #100,D2
0 0 1 0 0 1 0 0 0 0 1 1 1 1 0 0
Size Field
– 00 Byte Operation
– 01 Word Operation
– 10 Long Word Operation
– 11 Reserved
11
Hand Assembling (Move)
Translate: Move.L #100,D2
0010 0100 0011 1100 0000 0064
2 4 3 C 0000 0064
Enter code:
mm.w
10200000
243c
0
64 12
During Your Lab
DEC2BIN
Converts a decimal ASCII string to a binary number
Reads null-terminated string from A1 (doesn’t modify A1)
Converts ASCII bytes to decimal using Horner’s equation
Decimal: 3210 = (((3) * 10 + 2) * 10 + 1) * 10 + 0
Store result in D1
Write as subroutine (save registers to stack, use rts)
Hint: use a loop, multiply instruction, and accumulator
Hint: use data registers to hold temporary values
14
No error checking on input required
Post Lab Subroutines
BIN2DEC
Converts binary number to decimal ASCII string
Reads word-sized binary number from D1 (doesn’t modify it)
Writes null-terminated string at location in A2
Horner’s equation requires a divide subroutine
Hex: 3210 = (((3) * A + 2) * A + 1) * A + 0
16
Deliverables
LAB demo
3 marks – Lab completion (program must work 100%)
2 marks – Questions answered during lab demo
Individual mark
May be asked about the program and/or asked to hand assemble
Post lab
2 marks per subroutine (DEC2BIN & BIN2DEC)
19
20
21
22
23