CPE215 Lecture 31 - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

CPE215 Lecture 31

Description:

Opcode Mnemonic. Operand(s) Comment. Label and Comment are optional. MC68000 Syntax ... XREF permits access to external subroutines, such as those for keyboard input, ... – PowerPoint PPT presentation

Number of Views:56
Avg rating:3.0/5.0
Slides: 20
Provided by: markhutch4
Category:

less

Transcript and Presenter's Notes

Title: CPE215 Lecture 31


1
CPE-215 Lecture 31
  • Motorola Code

2
Line Fields
  • Each line in MC68000 is divided into four fields
  • Label
  • Opcode Mnemonic
  • Operand(s)
  • Comment
  • Label and Comment are optional.

3
MC68000 Syntax
  • Directives
  • XREF directive
  • Assembly Language Instructions
  • Data Section
  • DATA directive
  • Define Constant directives
  • Define Storage directives
  • End Directive

4
XREF Directives
  • XREF permits access to external subroutines, such
    as those for keyboard input, line termination,
    and display output.
  • Every assembler has a number of these, and they
    are linked in when the program is assembled.

5
Input/Output Routines
  • Each assembler has routines to get inputs from
    the keyboard and display outputs on the screen.
  • These are linked into the program in response to
    the XREF directive.
  • DECIN, DECIN__LONG
  • DECOUT, DECOUT__LONG
  • HEXIN, HEXIN__LONG
  • HEXOUT, HEXOUT__LONG
  • NEWLINE
  • STRIN
  • STROUT

6
STRIN
  • You need a buffer
  • bufname DS.B 80
  • The buffer address is loaded into A0
  • LEA bufname,A0
  • The buffer size is loaded into D0
  • MOVE.W 80,D0
  • Then you jump to the subroutine
  • JSR strin

7
Where Stuff Goes
  • Input subroutines store the input from the
    keyboard in register D0.
  • Output subroutines store whatever is in D0 to the
    display.
  • In the case of strings, A0 holds the address of
    the string or buffer, and D0 holds the length of
    the string or size of the buffer.

8
STROUT
  • You need a string
  • msg DC.B This string has 29 characters
  • The string address is loaded into A0
  • LEA msg,A0
  • The string size is loaded into D0
  • MOVE.W 29,D0
  • Then you jump to the subroutine
  • JSR strout

9
DATA Directive
  • This directive is used to define the beginning of
    the data section.

10
Data Directives
  • Define Constant
  • DC.ltsizegt ltconstantsgt
  • Can be Byte, Word, Long word
  • Define Storage
  • DS.ltsizegt ltcountgt
  • Can be Byte, Word, Long word
  • Not initialized
  • Define Constant Block
  • DCB.ltsizegt ltcountgt,ltvaluegt
  • Can be Byte, Word, Long word
  • All of these can be used to create arrays

11
Sample Program 1 -- Pascal
  • program example (output)
  • var
  • i, j, k integer
  • begin
  • i 75
  • j 4
  • k i j 6
  • writeln (k)
  • end.

12
Sample Program 1 -- C
  • include ltstdio.hgt
  • void main (void)
  • int i 75
  • int j 4
  • int k
  • k i j 6
  • printf (d\n, k)

13
MC68000 Code, Sample 1
  • xref decout, newline, stop
  • program instruction section
  • start move.w I,d0
  • add.w j,d0
  • subi.w 6,d0
  • move.w d0,k
  • jsr decout
  • jsr newline
  • jsr stop
  • data declaration section
  • data
  • i dc.w 75
  • j dc.w 4
  • k ds.w 1
  • end

14
MC68000 Code, Sample 2
  • This program computes 2n, where n is input.
  • Number must be in the range of 0 to 14.
  • The table entry for n is printed out.
  • NOTE This sample does not include any prompts
    for input, so the code could be improved vastly
    for user-friendliness.

15
Code for Sample 2
  • xref decout, decin, newline, stop
  • start lea p2table,a0
  • jsr decin
  • bmi out
  • cmpi.w 14,d0
  • bgt out
  • asl.w 1,d0
  • move.w (0,a0,d0.w),d0
  • jsr decout
  • jsr newline
  • out jsr stop
  • data
  • p2table dc.w 1,2,4,8,16,32,64,128,256,512,1024
  • dc.w 2048,4096,8192,16384
  • end

16
Sample 3, Subroutine
  • This program computes Y X2 X using a
    subroutine.
  • Since D1 is used as a scratch register by the
    subroutine, it must be pushed and popped within
    the subroutine.

17
Sample 3, Main Program
  • XREF DECOUT,NEWLINE,STOP
  • START MOVEQ 6,D1 Loop 7 times
  • MOVEQ 1,D2
  • LOOP MOVE.W D2,D0
  • JSR COMPUTE
  • JSR DECOUT
  • JSR NEWLINE
  • ADDQ.W 1,D2
  • DBRA D1,LOOP
  • JSR STOP
  • COMPUTE
  • END

18
Sample 3, Subroutine
  • COMPUTE MOVE.L D1,-(SP)
  • Push D1 on the stack
  • MOVE.W D0,D1
  • MULU D0,D1
  • ADD.W D1,D0
  • MOVE.L (SP),D1 Pop D1
  • RTS

19
Saving More Stuff
  • Save
  • MOVE.L A0,-(SP)
  • MOVE.L D2,-(SP)
  • MOVE.L D1,-(SP) MOVEA.L ?
  • or
  • MOVEM.L D1-D2/A0,-(SP)
  • Restore
  • MOVE.L (SP),D1
  • MOVE.L (SP),D2
  • MOVEA.L (SP),A0
  • or
  • MOVEM.L (SP),D1-D2/A0
Write a Comment
User Comments (0)
About PowerShow.com