Upload
others
View
0
Download
0
Embed Size (px)
Citation preview
1
EECE416 :Microcomputer Fundamentals and Design
68000 Programming Techniques
with EASY68K
2
Programming Techniques
Subroutines and Parameter PassingData gatheringSearching Data TableString OperationsSortingComputational RoutinesNumber ConversionExamples
3
Exercise I
TrapExample.x68Using different TRAPs for Key-In and Display⌧Trap task 5
• Read a character from keyboard• Stored the keyed-in in the D1.B
⌧Trap task 6• Display a character stored in D1.B
⌧Trap task 0 (with CR.LF)/1 (w/o CR.LF)• Display a string of characters whose starting address is stored
in A1 register• Display of the string continues until it meets number 0 [zero]
⌧Trap task12• Key echo-off (with D1.B=0)• Key echo-on (with D1.B=non zero value)
A character guessing game
4
Exercises (Password Echo)P-ECHO.x68
Accept 5-digit number, and display * for each digitAnd display at the next line the password
5
Tell me why we have to move around.
6
Exercises - continuedRevision of P-ECHO.asm to C-ECHO.asm
Allow only 5 times of Password Tries for ATM access
7
3 Subroutines for TRAP business
RCHRRead a characterInput: Key-inOutput: Key-in is stored in D1
PCHRPrint a characterInput: a character stored in D1Output: Display on Monitor
EOFFEcho-Off DeclarationCalled once at topInput: NoneOutput:None
8
Moving between Data registers and MemoryWhat if you need more than 7 long rooms?
Well, in memory, there are many byte rooms. Millions!
9
Exercise II (Moving to/from MEM)Storing Data Into Memory
10
Is this what will happen?
11
Exercise II-continued
This is what we want.
This is what we will have. Why?
12
ASCII Code Chart
13
ASCII-to-HEX Conversion
Task #5A Character (in ASCII code (of a Byte size)) in D1
Conversion of the Byte in ASCII into a Hex NumberNumeric or Alpha?
$30 - $39 D1=D1-$30$41 - $46 D1=D1-$37All others “error message”
14
Subroutine and StackSubroutine
Name= labelEnds with RTS
CallingCall by JSR or BSRChanging PC to the Label (or starting address) of a SubroutineProgram should know the return address after visiting the subroutine
StackThe return address (the address just after the calling instruction) is stored in the StackStack is also in the Memory (size of Long Word) starting @00000FF0 and decreasing. So, program code should not mess with stack memory area.The Stack address is stored in Address register, A7 (“stack pointer”)LIFO (Last In First Out) StructurePUSH and POP
PC gets “Address for next instruction” at the memory location pointed by A7
15
Subroutine and Stack
16
ATOH: ASCII to HEX Conversion Subroutine
17
Subroutine ATOH (ASCII-to-Hex)
18
Code structure for HEX-to-MEM
19
Running Result
20
Exercise III
Problem: Retrieve the long word (I.e., 4 bytes) stored at the location starting at $300, and print each byte, from highest to lowest, on the computer screen.This is what we want.
Need: Conversion of HEX to ASCII (HtoA)
21
Naïve Approach (without HtoA)
ASCII TreatmentTo MonitorFrom KeyboardThrough D1PCHR & RCHR
22
Hex to ASCII Conversion (HtoA)
23
Code StructureOverall Code
Start with A2H codeUse A2H for writing 4 hex bytes into MEMAdd new lines for retrieving and printing them
24
Code Run Example
25
Exercise IVDEC to HEX Conversion
26
DEC to HEX Conversion – Background
27
Pre-ProcessingDeclaration of Memory Location by Label
Read 3 digit Decimal NumberStore each digit from $500 as Number (by calling AtoHsubroutine)
28
DtoH - SubroutineRead 3 numbers starting from $500 and store into Data RegistersConvert them into 3 hex digitsStore hex bytes starting from $503
29
DtoH (subroutine code)
30
The Last Step & OverallThe last step:
Read each Hex byte starting from $503Convert each Hex to ASCII (by calling HtoAsubroutine) then Display (by PCHR)
Overall Structure1. Pre-Processing2. Call DtoH subroutine3. Last Step
31
Run Result and Memory Contents
32
68K Coding ProjectCoding Problem:
Convert the keyed-in “Dotted Decimal IP address”into “8-digit HEX number” and display the number AND its class (A – E)The number of digits of each decimal number can be 1, 2, or 3. The last decimal number does not have ‘dot’The ‘Enter’ key indicates the end of the IP address input.
Submission InstructionOverall code structure in the register and memory level details.Code with plenty of comments (almost every line of instruction)Deadline: TBD
33
IP Address & Result Display Example