Assembly Language. Operand Size. The internal registers. Computers operate on chunks of data composed of a particular number of bits.

Similar documents
Multiplies the word length <ea> times the least significant word in Dn. The result is a long word.

Module 7: Address Registers & Array Processing

68000 Architecture, Data Types and Addressing Modes. 9/20/6 Lecture 2 - Prog Model 1

68000 Instruction Set (2) 9/20/6 Lecture 3 - Instruction Set - Al 1

... Executing conditional instructions

Tutorial 1 Microcomputer Fundamentals

Addressing Modes. To review data transfer instructions and applying the more advanced addressing modes.

Physics 116B Winter 2006: Problem Assignment 8

Lab Cover Page. Lab Date and Time: Teaching Assistant to whom you are submitting

CPE/EE 421 Microcomputers

Section 1--Computer architecture: organization of the cpu and memory, address and data bus, fetch-execute cycle

Machine Language and Assembly Language

SEE 3223 Microprocessors. 4: Addressing Modes. Muhammad Mun im Ahmad Zabidi

Alex Milenkovich 1. CPE/EE 421 Microcomputers: Motorola 68000: Architecture & Assembly Programming. Outline

68000 Assembler by Paul McKee. User's Manual

68000 Architecture. To review the the architecture of the microprocessor.

EECE416 :Microcomputer Fundamentals and Design Instruction Sets and Groups

Computer Architecture 5.1. Computer Architecture. 5.2 Vector Address: Interrupt sources (IS) such as I/O, Timer 5.3. Computer Architecture

Mark Redekopp, All rights reserved. EE 357 Unit 4b. CF Assembly Basics

CPE/EE 421 Microcomputers

INTRODUCTION TO BRANCHING. There are two forms of unconditional branching in the MC68000.

CPE/EE 421 Microcomputers

Alex Milenkovich 1. CPE/EE 421 Microcomputers: Motorola 68000: Assembly Language and C. Outline

CS401 - Computer Architecture and Assembly Language Programming Glossary By

stack frame where register An is used as the argument pointer.

Lecture 5 Assembly Programming: Arithmetic

PART II: Cap. 6 - Linguaggio macchina M68000

Lab Reports. Program Description (separate page - ONLY IF REQUIRED)

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

17. Instruction Sets: Characteristics and Functions

Program Development. Chapter 5

INTRODUCTION TO BRANCHING

Lab 2 Use Traps. Lab 2 Input and Output 2 nd Semester. Lab 2 English. Lab 2 Pseudocode

Interfacing Compiler and Hardware. Computer Systems Architecture. Processor Types And Instruction Sets. What Instructions Should A Processor Offer?

Chapter 2 Instruction Set Architecture

Chapter 7 Central Processor Unit (S08CPUV2)

SISTEMI EMBEDDED. Basic Concepts about Computers. Federico Baronti Last version:

ENE 334 Microprocessors

Trap Vector Table. Interrupt Vector Table. Operating System and Supervisor Stack. Available for User Programs. Device Register Addresses

1. bit manipulation instructions such as BTST, BCHG

ARM Assembly Language. Programming

Intel 8086: Instruction Set

Student # (In case pages get detached) The Edward S. Rogers Sr. Department of Electrical and Computer Engineering

Practical Malware Analysis

H8/300L Series Programming Manual

Wednesday, September 13, Chapter 4

MC9S12 Assembler Directives A Summary of MC9S12 Instructions Disassembly of MC9S12 op codes. Summary of HCS12 addressing modes ADDRESSING MODES

Instruction Sets: Characteristics and Functions

Wednesday, February 4, Chapter 4

EE 5340/7340 Motorola 68HC11 Microcontroler Lecture 1. Carlos E. Davila, Electrical Engineering Dept. Southern Methodist University

CSC 220: Computer Organization Unit 12 CPU programming

Menu Computer Organization Programming Model for the an example microprocessors (the G-CPU & Motorola 68HC11) Assembly Programming Look into my...

LECTURE #21: G-CPU & Assembly Code EEL 3701: Digital Logic and Computer Systems Based on lecture notes by Dr. Eric M. Schwartz

Subroutines. passing data

Levels of Programming. Registers

CPE300: Digital System Architecture and Design

ME4447/6405. Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics. Instructor: Professor Charles Ume LECTURE 7

UNIMPLEMENTED INSTRUCTIONS

appendix a The LC-3 ISA A.1 Overview

EC 413 Computer Organization

Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2

Assembly Language. Instructor: Dmitri A. Gusev. Spring Lecture 10, February 27, CSC : Introduction to Computer Science

ECOM 2325 Computer Organization and Assembly Language. Instructor: Ruba A.Salamah INTRODUCTION

2010 Summer Answers [OS I]

CSIS1120A. 10. Instruction Set & Addressing Mode. CSIS1120A 10. Instruction Set & Addressing Mode 1

Assembly Assignment 6 - Lottery

COMPUTER ORGANIZATION & ARCHITECTURE

1. Introduction to Assembly Language

Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine

Today s objective: introduction to really simple subroutines to simplify program structure for I/O

Assembler Directives and Programming

Stored Program Concept. Instructions: Characteristics of Instruction Set. Architecture Specification. Example of multiple operands

CSCI 402: Computer Architectures. Instructions: Language of the Computer (1) Fengguang Song Department of Computer & Information Science IUPUI

ECE 154A Introduction to. Fall 2012

We can study computer architectures by starting with the basic building blocks. Adders, decoders, multiplexors, flip-flops, registers,...

Processor design - MIPS

Chapter 1. Computer Abstractions and Technology. Lesson 3: Understanding Performance

Assembly Programming

Topics Power tends to corrupt; absolute power corrupts absolutely. Computer Organization CS Data Representation

LAB 1: MC68000 CPU PROGRAMMING DATA TRANSFER INSTRUCTIONS

CPE 323 MSP430 INSTRUCTION SET ARCHITECTURE (ISA)

Contents. Slide Set 1. About these slides. Outline of Slide Set 1. Typographical conventions: Italics. Typographical conventions. About these slides

Instruction Set II. COMP 212 Computer Organization & Architecture. COMP 212 Fall Lecture 7. Instruction Set. Quiz. What is an Instruction Set?

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

Chapter 4. MARIE: An Introduction to a Simple Computer

Assembly Language Programming

ELEC / Computer Architecture and Design Fall 2013 Instruction Set Architecture (Chapter 2)

Overview. Introduction to the MIPS ISA. MIPS ISA Overview. Overview (2)

The CPU and Memory. How does a computer work? How does a computer interact with data? How are instructions performed? Recall schematic diagram:

2.2 THE MARIE Instruction Set Architecture

reply db y prompt db Enter your favourite colour:, 0 colour db 80 dup(?) i db 20 k db? num dw 4000 large dd 50000

19 Much that I bound, I could not free; Much that I freed returned to me. Lee Wilson Dodd

Mark Redekopp, All rights reserved. EE 357 Unit 5. Assembler Directives and Programming

3/21/2009. Lecture 15: Data Structure & Parameter Passing. Define Constants with EQU. Define Variables with DC and DS. Define Variables with DC and DS

Chapter 2A Instructions: Language of the Computer

CSEE 3827: Fundamentals of Computer Systems


Recursive Subroutine Calls Example

Bits, Words, and Integers

Sparse Notes on an MIPS Processor s Architecture and its Assembly Language

Transcription:

1 2 Chapter 6 Assembly Language Operand Size 8 bits 16 bits Computers operate on chunks of data composed of a particular number of bits. The 68K has a 32-bit architecture and a 16-bit organization. Internal registers hold 32 bits Can perform operations on 32-bits Has a 16 bit external data bus - operands must be moved in and out of memory as two 16 bit words Some internal data paths are 16 bit. 68K can handle 16 bit and 8 bit values. 1001 1002 1003 1004 1005 1006 1007 Byte-wide memory 1002 1004 1006 1008 100A 100C 100E Word -wide memory The 68K has a byte-addressable architecture Successive bytes are stored at consecutively numbered byte addresses Any byte can be individually written to or read from. 16-bit words are composed of 2 bytes and are stored at consecutive even addresses: 0,2,4,... 32-bit longwords are stored at addresses 0, 4, 8, 12... 1004 1008 100C 1010 1014 1018 101C 32 bits Longword-wide memory 3 4 When we store a 32 bit longword, where do the bytes go? Consider the example of storing $12345678 into memory location $. The 68K would store it as : 12 34 56 78 Where the most significant byte is at the lowest address. This order is called Big -Endian. If the bytes are stored in the opposite order, with the most significant byte at the highest address like: 78 56 34 12 Where the least significant byteis at the lowest address, we call the order Little-Endian. When we encounter a command like MOVE.W DO,1234 The following bit copy is performed: In th 68K all addresses are 32 bit values This should allow for an address space of 2 32 bytes = 4 G of memory. Here 2 10 =1024 1 K 2 20 =1,048,576 1M, 2 30 = 1,073,741,824 1 G However, the original design was for a 64 pin package which limited it somewhat. The address bits A 24-A 31 are not connected to pins and cannot access memory. This effectively forces the address bus to 24 bits and the original 68K can only access 2 24 = 2 4 2 20 or 16 M of memory. The internal registers The 68K has a register-to -memory architecture. This means typical instructions will specify one operand in memory and the others as a register like: ADD $1234,D0 1232 d 08 -d 15 d 00 -d 07 which causes the contents of location $1234 to be added to D0 1234 1235 The 68K consists of 8 32-bit data registers, 8 32-bit address registers, an 8 bit condition code register, an 8 bit status byte (used by operating system to define the operating mode of the 68K) and a 32-bit program counter.

5 6 The programmer's view of the 68K: d 16 d 15 d 00 d 31 d 08 d 07 D0 D1 D2 D3 D4 D5 D6 D7 a 31 a 16 a 15 a 00 A0 A1 A2 X N Z V C A3 A4 A5 A6 A7 PC CCR All of the data registers are general-purpose, commands which can be applied to D0 can be applied to any data register. We know one advantage of multiple data registers is to store frequently used data on chip for quicker access. The number of internal data registers is a function of economics. Most instructions store the op -code and operand register in a 16-bit word. It requires 3 bits to describe the 8 data registers. More registers would require more bits, leaving fewer bits dedicated to opcode and hence fewer instructions capable of being described in this length word. Memory requires a 32 bit specification. Instructions that access memory are longer than instructions that access registers. Most high level languages do not allow for the programmer to specify the use of registers for variable allocation this is the compilers job. ************************************************************ C is one of the exceptions: In C there is a storage class specifier called register. It can be applied to local variables and formal parameters in functions. The class specifier is intended to be used where many references will be made to the same variable. The register specifier originally applied only to variables of type int or char (and indeed the C standard permits the compiler to ignore the specifier the current standards state "access to the object be as fast as possible") 7 8 Some C code: int int_power(register int m, register int e) { register int temp; temp=1; for ( ; e ; e--) temp=temp*m; return temp; } Recall we specify operations as either byte, word or longword operations by appending the.b,.w or.l to the mnemonic. Each affects a certain sequence of bits of the operand:.b D 00 D 07.W D 00 - D 15 The remaining bits would remain unchanged. CLR.W D1 Would force the low 16 bits of D1 to 0's The number of actual register variables permitted depends on the environment and implementation of C. For the sake of portability if no registers are available the compiler w ill automatically transform register variables to non register variables, if needed. ********************************************************** When referring to the bits of a data register (for purposes of RTL) we will denote consecutive bits i to j in register Dn by Dn(i:j). If we wanted to refer to bits 16 through 31 of register D5 we would write D5(16,31) D1 XXXXXXXXXXXXXXXX0000000000000000 Where X stands for whatever was already there. If [D1] = $12345678 then after CLR.W D1 we have [D1] =$12340000 Assembly form RTL form ADD.L D0,D1 [D1(0:31)] [D1(0:31)]+[D0(0:31)] ADD.W D0,D1 [D1(0:15)] [D1(0:15)]+[D0(0:15)] ADD.B D0,D1 [D1(0:7)] [D1(0:7)]+[D0(0:7)] We can omit the slice notation unless we are meaning to emphasize what bits we are working on.

9 10 The affect on the carry bit of the.b,.w or.l is determined only by the corresponding bits for that size operation. Consider the following example: [D0] = $12345678, [D1] = $ABCDEF98 In hexadecimal 68K Address Registers The 68K's eight 32-bit address registers A0 A7 act as pointer registers, since they hold the address of some memory location. This will be important wen dealing with arrays, matrices, tables and vectors. 12345678 +ABCDEF98 BE024610 5678 + EF98 14610 78 + 98 110 A0 A6 are identical in the way they are treated. A7 has the additional responsibility of being a stack pointer for storing subroutine addresses. Assemble code Register D1 CCR carry bit C ADD.B D0,D1 [D1]=ABCDEF10 [C] = 1 ADD.W D0,D1 [D1]=ABCD4610 [C] = 1 ADD.L D0,D1 [D1]=BE024610 [C] = 0 It is easy to make an error if we do not pay attention to using consistent size operations on data registers. Consider the following: MOVE.B XYZ,D0 Copy contents of location XYZ to D0 SUB.B #5,D0 Subtract 5 from D0 CMP.W #12,D0 IS D0 > 12 BGT Test Branch on Greater than Notice on the MOVE.B we are only changing bytes d 00 d 07. The same is true when we subtract 5 from D0. When we get to the third step, however we are comparing d 00 d 15 to the word representation of 12. The problem is we don't have any idea what is in d 08 d 15. We may or may not wind up with the desired result. Many of the operations we did with data registers can be done with address registers with a few differences: Operations on address registers do not normally affect the CCR's bits All operations on the address registers are longword operations (Ai's are treated as single entities. Any.W operation is automatically extended to a.l operation.b operations are not permitted The contents of an address are treated as a signed 2's complement value. Performing a.w operation causes the sign bit to be extended from A 15 to A 16 A 31. MOVE.W #$8022,A1 (8022 16=00000010 2) has the effect [A1] $FFFF8022 11 12 MOVE.W #$6121,A2 (6121 16= 01010001 2) has the effect [A2] $00006121 Why do we allow for negative addresses? We can interpret a negative address as a move backwards. Example: Suppose A1 contains 1280 and A2 contains -40. Adding A1 and A2 results in a composite address 1240, 40 units in address lower than A1. The 68K has special mnemonics for operations that modify addresses. Some examples (destination operand is address register) ADDA.L D1,A3 ADDA = add to address register MOVEA.L D1,A2 MOVEA = move to address register SUBA.W D1,A3 SUBA=subtract from address register Using an address register to access a data element: A0 Contains address of the start of data structure A1 Will contain address of start of ith element D0 i MULU #12,D0 MOVEA.L A0,A1 ADDA.L D0,A1 12-byte data block item 0 12-byte data block item i 12-byte data block item 49 Calculate offset Copy base address to A1 Add offset to A1 Example: Address register A0 points to the beginning of a data structure in memory. The structure is made up of 50 items numbered 0 through 49. Each of the 50 items i s 12 bytes long. D0 contains the number of the item w wish to access. We wish to put the address of the item in A1. We will use the operation MULU #n,di which multiplies the 16-bit low order word in Di by n and puts a 32-bit product in Di As you can see the instruction set is rather primitive compared to high level languages. Any type of complex operation will be implemented by a sequence of primitive instructions.

13 14 An Introduction to the 68K instruction set Data Movement The largest set of instructions in most programs are for data movement. When we omit the.w,.l or.b qualifier we will assume a default of.w, where it makes sense. Two-operand instructions will have the format Operation source,destination Example: MOVE D3,D4 copies the contents of D3 into D4 Some 68K movement instructions Assembly RTL MOVE Di,Dj [Dj] [Di] MOVE P,Di [Di] [M(P)] MOVE Di,P [M(P)] [Di] EXG Di,Dj [TEMP] [Di], [Di] [Dj], [Dj] [TEMP] SWAP Di [Di(0:15)] [Di(16:31)], [Di(16:31)] [Di(0:15)] LEA P,Ai [Ai] P LEA Load Effective Address In the next example we will demonstrate these instructions using our assembler: Create a text file: samp.x68 ORG $ MOVE.L #$12345678,D0 MOVE.B D0,D1 MOVE.W D0,D2 MOVE.L D0,D3 EXG D0,A0 SWAP D3 MOVEA.L data,a1 LEA data,a1 STOP #$2700 DATA DC.L $ABCDDCBA END $ From the DOS prompt type (and see the respone): C:\WINDOWS\Desktop\assem\68Ksim>x68k samp -L [X68K PC-2.2 Copyright (c) University of Teesside 1989,99] No errors reported. Two Files should have been created in your directory : Samp.bin, Samp.lis First we will look at Samp.lis to see what the assembler did 15 16 Samp.lis (you should be able to open this with any text editor) Source file: SAMP.X68 Assembled on: 01-10-30 at: 07:01:50 by: X68K PC-2.2 Copyright (c) University of Teesside 1989,99 Defaults: ORG $0/FORMAT/OPT A,BRL,CEX,CL,FRL,MC,MD,NOMEX,NOPCO 1 0000 ORG $ 2 0000 203C12345678 MOVE.L #$12345678,D0 3 00001006 1200 MOVE.B D0,D1 4 00001008 3400 MOVE.W D0,D2 5 0000100A 2600 MOVE.L D0,D3 6 0000100C C188 EXG D0,A0 7 0000100E 4843 SWAP D3 8 00001010 227900001020 MOVEA.L DATA,A1 9 00001016 43F900001020 LEA DATA,A1 10 0000101C 4E722700 STOP #$2700 11 00001020 ABCDDCBA DATA: DC.L $ABCDDCBA 12 0000 END $ Lines: 12, Errors: 0, Warnings: 0. Next we will use the simulator to run our assembled code: C:\WINDOWS\Desktop\assem\68Ksim>e68k samp [E68K PC-2.2i Copyright (c) University of Teesside 1989,99] Address space 0 to ^10485759 (10240 kbytes). Loading binary file "SAMP.BIN". Start address: 00, Low: 0000, High: 00001023 At this point we will create a log of our interaction with the simulator at the '>' prompt type : log fun.log > log fun.log I will step through the program, and when done show y'all the Log file. (remember typing "quit" at the simulators prompt will quit the simulator, df display formatted registers and tr- trace, to exit trace mode type a '.') Logging to "FUN.LOG" started. >df PC=00 SR=2000 SS=00A00000 US=00000000 X=0 D0=00000000 D1=00000000 D2=00000000 D3=00000000 V=0 ---------->MOVE.L #$12345678,D0 >tr PC=001006 SR=2000 SS=00A00000 US=00000000 X=0 D0=12345678 D1=00000000 D2=00000000 D3=00000000 V=0 ---------->MOVE.B D0,D1 PC=001008 SR=2000 SS=00A00000 US=00000000 X=0 D0=12345678 D1=00000078 D2=00000000 D3=00000000 V=0 ---------->MOVE.W D0,D2 PC=00100A SR=2000 SS=00A00000 US=00000000 X=0 D0=12345678 D1=00000078 D2=00005678 D3=00000000 V=0 ---------->MOVE.L D0,D3 PC=00100C SR=2000 SS=00A00000 US=00000000 X=0 D0=12345678 D1=00000078 D2=00005678 D3=12345678 V=0 ---------->EXG D0,A0 PC=00100E SR=2000 SS=00A00000 US=00000000 X=0 A0=12345678 A1=00000000 A2=00000000 A3=00000000 N=0 D0=00000000 D1=00000078 D2=00005678 D3=12345678 V=0 ---------->SWAP D3

17 18 PC=001010 SR=2000 SS=00A00000 US=00000000 X=0 A0=12345678 A1=00000000 A2=00000000 A3=00000000 N=0 ---------->MOVEA.L $1020,A1 PC=001016 SR=2000 SS=00A00000 US=00000000 X=0 A0=12345678 A1=ABCDDCBA A2=00000000 A3=00000000 N=0 ---------->LEA.L $1020,A1 PC=00101C SR=2000 SS=00A00000 US=00000000 X=0 A0=12345678 A1=00001020 A2=00000000 A3=00000000 N=0 ---------->STOP #$2700 Processor halted at: 001020 PC=001020 SR=2700 SS=00A00000 US=00000000 X=0 A0=12345678 A1=00001020 A2=00000000 A3=00000000 N=0 ---------->DC.W $ABCD Returning to command-mode after "OPCODE 1010 EMULATION" exception. Arithmetic and Logical operations Asembly Form RTL ADD Di,Dj [Dj] [Di] + [Dj] ADDX Di,Dj [Dj] [Di] + [Dj] + [X] SUB Di,Dj [Dj] [Di] - [Dj] SUBX Di,Dj [Dj] [Di] + [Dj] - [X] MULU Di,Dj [Dj(0:31)] [Di(0:15)] [Dj(0:15)] DIVU Di,Dj [Dj(0:15)] [Dj(0:31)]/ [Di(0:15)] integer part [Dj(16:31)] remainder NEG Di [Di] 0 [Di] NEGX Di [Di] 0 - [Di] [X] AND Di,Dj [Dj] [Di] [Dj] OR Di,Dj [Dj] [Di]+[Dj] EOR Di,Dj [Dj] [Di] [Dj] NOT Dj [ Dj] [ Dj] >quit Here [X] is the contents of the X bit of the CCR (usually a copy of the carry bit) The multiplication and division are specific with regards to what they operate on. The other operations can be designated.b,.l or.w 19 20 MULU Di,Dj [Dj(0:31)] [Di(0:15)] [Dj(0:15)] Multiplies two 16 bit operands and stores as 32 bit result Suppose D0 = $1234 and D1=$0202 Then MULU D0,D1 leaves $00248C68 in D1 DIVU Di,Dj [Dj(0:15)] [Dj(0:31)]/ [Di(0:15)] integer part [Dj(16:31)] remainder Divides a 32 bit operand by a 16 bit operand and stores as a 32 bit result with the low 16 bits being the quotient and the high 16 bits the remainder. Suppose D1 = $2131 2131 16 = 8497 10 and D0=$4 Then DIVU D0,D1 leaves $0001084C in D1 (8497/4 = 2124 R 1, and 2124 10=84C 16) Another point: Computers execute instructions even if the instructions don't make sense. Higher level languages are often strongly typed and would prevent the programmer from doing such things. Consider the following assembly language program that adds the ASCII representation for character 'A' to that of character 'B' The code: ORG $ MOVE.B Char1,D0 MOVE.B Char2,D1 ADD.B D0,D1 STOP #$2700 Char1 DC.B 'A' Char2 DC.B 'B' END $ The.lis file after assembled: Source file: SAMP.X68 Assembled on: 01-10-30 at: 09:54:45 by: X68K PC-2.2 Copyright (c) University of Teesside 1989,99 Defaults: ORG $0/FORMAT/OPT A,BRL,CEX,CL,FRL,MC,MD,NOMEX,NOPCO 1 0000 ORG $ 2 0000 103900001012 MOVE.B CHAR1,D0 3 00001006 123900001013 MOVE.B CHAR2,D1 4 0000100C D200 ADD.B D0,D1 5 6 0000100E 4E722700 STOP #$2700 7 00001012 41 CHAR1: DC.B 'A' 8 00001013 42 CHAR2: DC.B 'B' 9 0000 END $ Lines: 9, Errors: 0, Warnings: 0. The Log file for a run: Logging to "FUN.LOG" started. >df PC=00 SR=2000 SS=00A00000 US=00000000 X=0 D0=00000000 D1=00000000 D2=00000000 D3=00000000 V=0 ---------->MOVE.B $1012,D0 >tr PC=001006 SR=2000 SS=00A00000 US=00000000 X=0 D0=00000041 D1=00000000 D2=00000000 D3=00000000 V=0 ---------->MOVE.B $1013,D1

21 22 PC=00100C SR=2000 SS=00A00000 US=00000000 X=0 D0=00000041 D1=00000042 D2=00000000 D3=00000000 V=0 ---------->ADD.B D0,D1 PC=00100E SR=200A SS=00A00000 US=00000000 X=0 A0=00000000 A1=00000000 A2=00000000 A3=00000000 N=1 D0=00000041 D1=00000083 D2=00000000 D3=00000000 V=1 ---------->STOP #$2700 Processor halted at: 001012 PC=001012 SR=2700 SS=00A00000 US=00000000 X=0 D0=00000041 D1=00000083 D2=00000000 D3=00000000 V=0 ---------->DC.W $4142 quit What is the meaning of what is in D1? 2 2 X + Y Here is a program to calculate Z = X Y For X=50, Y=12 50 + 12 Answer should be : 69.5789 50 12 2 2 Or = 69 R 22 The assembly code: ORG $ X DC.W 50 ;value for x Y DC.W 12 ;value for y Z DS.W 1 ;create space for result ORG $1200 MOVE.W X,D0 ;Copy X to D0 MULU D0,D0 ;square X MOVE.W Y,D1 ;Copy Y to D1 MULU D1,D1 ;square Y ADD.L D0,D1 ; X^2 +Y^2 into D1 MOVE.W X,D0 ;Copy X to D0 SUB.W Y,D0 ; X-Y in D0 DIVU D0,D1 ;put(x^2+y^2)/(x-y)into D0 MOVE.W D1,Z ;Put result out to memory Z STOP #$2700 END $1200 ;End with address entry point The assembled code : Source file: SAMP.X68 Assembled on: 01-10-30 at: 14:16:33 by: X68K PC-2.2 Copyright (c) University of Teesside 1989,99 Defaults: ORG $0/FORMAT/OPT A,BRL,CEX,CL,FRL,MC,MD,NOMEX,NOPCO 1 0000 ORG $ 2 0000 0032 X: DC.W 50 3 00001002 000C Y: DC.W 12 4 00001004 00000002 Z: DS.W 1 5 00001200 ORG $1200 6 00001200 3038 MOVE.W X,D0 7 00001204 C0C0 MULU D0,D0 8 00001206 32381002 MOVE.W Y,D1 9 0000120A C2C1 MULU D1,D1 10 0000120C D280 ADD.L D0,D1 11 0000120E 3038 MOVE.W X,D0 12 00001212 90781002 SUB.W Y,D0 13 00001216 82C0 DIVU D0,D1 14 00001218 31C11004 MOVE.W D1,Z 15 0000121C 4E722700 STOP #$2700 16 00001200 END $1200 Lines: 16, Errors: 0, Warnings: 0. 23 24 The log file (with comment) Logging to "FUN.LOG" started. >df PC=001200 SR=2000 SS=00A00000 US=00000000 X=0 D0=00000000 D1=00000000 D2=00000000 D3=00000000 V=0 ---------->MOVE.W $,D0 >tr PC=001204 SR=2000 SS=00A00000 US=00000000 X=0 D0=00000032 D1=00000000 D2=00000000 D3=00000000 V=0 ---------->MULU.W D0,D0 50 10= 32 16 PC=001206 SR=2000 SS=00A00000 US=00000000 X=0 D0=000009C4 D1=00000000 D2=00000000 D3=00000000 V=0 ---------->MOVE.W $1002,D1 50 2 10 = 2500 10=9C4 16 PC=00120A SR=2000 SS=00A00000 US=00000000 X=0 D0=000009C4 D1=0000000C D2=00000000 D3=00000000 V=0 ---------->MULU.W D1,D1 12 10=C 16 PC=00120C SR=2000 SS=00A00000 US=00000000 X=0 D0=000009C4 D1=00000090 D2=00000000 D3=00000000 V=0 ---------->ADD.L D0,D1 12 2 10=144 10 =90 16 PC=00120E SR=2000 SS=00A00000 US=00000000 X=0 D0=000009C4 D1=00000A54 D2=00000000 D3=00000000 V=0 ---------->MOVE.W $,D0 50 2 10+12 2 10=2644 10=A54 16 PC=001212 SR=2000 SS=00A00000 US=00000000 X=0 D0=00000032 D1=00000A54 D2=00000000 D3=00000000 V=0 ---------->SUB.W $1002,D0 Copied 50 10 into D0 PC=001216 SR=2000 SS=00A00000 US=00000000 X=0 D0=00000026 D1=00000A54 D2=00000000 D3=00000000 V=0 ---------->DIVU.W D0,D1 Subtracted 12 10 from 50 10 and put in D0, D0=38 10 = 26 16 PC=001218 SR=2000 SS=00A00000 US=00000000 X=0 D0=00000026 D1=00160045 D2=00000000 D3=00000000 V=0 ---------->MOVE.W D1,$1004 A54 16 =2644 10 / 38 10 = 69 10 R 22 10 = 45 16 R 16 16

25 PC=00121C SR=2000 SS=00A00000 US=00000000 X=0 D0=00000026 D1=00160045 D2=00000000 D3=00000000 V=0 ---------->STOP #$2700 Processor halted at: 001220 PC=001220 SR=2700 SS=00A00000 US=00000000 X=0 D0=00000026 D1=00160045 D2=00000000 D3=00000000 V=0 ---------->ORI.B #$00,D0 MD - Memory Display command MD 00 00 32 00 0C 00 45 00 00 00 00 00 00 00 00 00 00 001010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00q >quit