33
1 EECE416 :Microcomputer Fundamentals and Design 68000 Programming Techniques with EASY68K

EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

1

EECE416 :Microcomputer Fundamentals and Design

68000 Programming Techniques

with EASY68K

faculty
Typewritten Text
WWW.MWFTR.COM
Page 2: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

2

Programming Techniques

Subroutines and Parameter PassingData gatheringSearching Data TableString OperationsSortingComputational RoutinesNumber ConversionExamples

Page 3: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

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

Page 4: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

4

Exercises (Password Echo)P-ECHO.x68

Accept 5-digit number, and display * for each digitAnd display at the next line the password

Page 5: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

5

Tell me why we have to move around.

Page 6: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

6

Exercises - continuedRevision of P-ECHO.asm to C-ECHO.asm

Allow only 5 times of Password Tries for ATM access

Page 7: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

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

Page 8: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

8

Moving between Data registers and MemoryWhat if you need more than 7 long rooms?

Well, in memory, there are many byte rooms. Millions!

Page 9: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

9

Exercise II (Moving to/from MEM)Storing Data Into Memory

Page 10: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

10

Is this what will happen?

Page 11: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

11

Exercise II-continued

This is what we want.

This is what we will have. Why?

Page 12: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

12

ASCII Code Chart

Page 13: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

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”

Page 14: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

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

Page 15: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

15

Subroutine and Stack

Page 16: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

16

ATOH: ASCII to HEX Conversion Subroutine

Page 17: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

17

Subroutine ATOH (ASCII-to-Hex)

Page 18: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

18

Code structure for HEX-to-MEM

Page 19: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

19

Running Result

Page 20: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

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)

Page 21: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

21

Naïve Approach (without HtoA)

ASCII TreatmentTo MonitorFrom KeyboardThrough D1PCHR & RCHR

Page 22: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

22

Hex to ASCII Conversion (HtoA)

Page 23: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

23

Code StructureOverall Code

Start with A2H codeUse A2H for writing 4 hex bytes into MEMAdd new lines for retrieving and printing them

Page 24: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

24

Code Run Example

Page 25: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

25

Exercise IVDEC to HEX Conversion

Page 26: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

26

DEC to HEX Conversion – Background

Page 27: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

27

Pre-ProcessingDeclaration of Memory Location by Label

Read 3 digit Decimal NumberStore each digit from $500 as Number (by calling AtoHsubroutine)

Page 28: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

28

DtoH - SubroutineRead 3 numbers starting from $500 and store into Data RegistersConvert them into 3 hex digitsStore hex bytes starting from $503

Page 29: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

29

DtoH (subroutine code)

Page 30: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

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

Page 31: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

31

Run Result and Memory Contents

Page 32: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

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

Page 33: EECE416 :Microcomputer Fundamentals and Design · Subroutine and Stack. aSubroutine `Name= label `Ends with . RTS. aCalling `Call by . JSR. or . BSR `Changing PC to the Label (or

33

IP Address & Result Display Example