Академический Документы
Профессиональный Документы
Культура Документы
Language
LANGUAGE is a medium of communication between two or more individuals or parties. The most important criteria in the communication is the message it brings must be effectively delivered, this is achieved only if the language is understood by the both parties. What if the language is not compatible to both parties? Then a translator is needed. For instance, a Japanese requires a Japanese-Malays translator to communicate to a Malaysian
Introduction Microprocessor run the operation based on the program that write by the programmer Three types of program language
High Level Language C,C++, BASIC, PASCAL, FOTRAN, JAVA Low Level Language Assembly Language Machine Language
How ever microprocessor does not understand what language write by the programmer
Block Diagram
BASIC COMMUNICATION COMPUTER SYSTEM COMMUNICATION Programmers Japanese Language Assembly Language Translator Japanese-Malay translator Language Malay Machine Language Machine Language Low level Compiler Assembler
High-level Language
High level
Middle level
Computer
COMPILERS
High level language (Basic, Pascal and C) Programming instructions in the normal English words, very friendly to programmers.. Middle level language (Assembly language) Programming instructions in the English like abbreviation, still not so user friendly. ASSEMBLER
Low level language (Machine language) Programming instructions in the binary codes, understand directly by computer system.
Programming language close to human language (such as English) is called high-level language. Examples of highlevel language such as FORTRAN, COBOL, BASIC, PASCAL, C + +, JAVA High level language similar to English. Instruction program written using English words, such as print, and other inputs. But every high-level language has its own rules or grammar for writing instruction program. Regulations referred to as syntax. Program written in the levels should be translated into machine code prior to running. Every high level language has its own translator program.
Assembly Language program consists of series of lines of Assembly language instructions. Deals directly with the internal structure of CPU Instruction consists of a mnemonic and two operands. Mnemonics (abbreviations) are used for the instructions of the processor
Names for memory locations Labels Symbols Design of processor must be known
Machine Language
Programs consist of 0s and 1s are called machine language. Assembly Languages provided mnemonics for machine code instructions. Mnemonics refer to codes and abbreviations to make it easier for the users to remember.
shows the instructions of three different languages that perform the same task.
Machine language +1300042774 +1400593419 +1200274027 Assembly Language LOAD BASEPAY ADD OVERPAY STORE GROSSPAY High-Level Language grosspay = basepay + overTimepay
Instructions are binary codes. Understand directly by computer system. Cumbersome for human.
Programming in Assembler
00110000001111000000000000010010
MOVE.W #$12,D0
00
11
000 000
(Data register direct addressing mode, D0)
A Simple Example
Write the instructions to add 50 and 72 and save the answer in register C.
High Level - Java, C
X = 50 + 72
Machine Language
HEX 3E 32 06 48 80 4F 76 BINARY 0011 1100 0011 0010 0000 0110 0100 1000 1000 0000 0100 1111 0111 0110 OPERAND MVI A 50 MVI B 72 ADD B MOV C, A HLT
The Assembler
Assembly Language:
Machine Language:
00110000001111000 01100100011110000 00000000110100
Binary
MOVE.B
#%10010101,D0
10010101B = 95H
D0 =
Octal
MOVE.B
#@45,D0
45O = 25H
D0 =
Hexadecimal
MOVE.B
#$FE,D0
D0 =
Decimal
MOVE.B
#10,D0
10D = 0AH
D0 =
ASCII Characters
D0 =
Easy68k Interface
PROGRAM DESCRIPTION
VARIABLES/PARAMETERS
Label:
Marks memory locations using characters. Easy reference. What instruction to execute. Usually specifies source & destination. May specify parameters as well. Used to describe flow of program,
Op-Code - Instruction:
Operand(s): Variables/Parameters:
Comment:
Simulation Window
Press here to execute programs step-by-step. Press here to restart program execution.
MOVE.B #9,D0 instruction: Is on line 11 in M68k source file. Is stored in memory address $1000. Its machine code is $103C0009 (00010000001111000000000000001001).
M68k needs to know where to start executing instructions, where to stop. Specified using ORG (Origin), END (End). Value of ORG loaded into PC, execution starts there.
Program Instructions
END $1000
Use Labels
Any memory location may be given labels. Easier to refer to specific locations:
Assembler format
Concept of programming
A program is a means to perform tasks or solve problems. Thus in the process of program building consists several essential steps:
Definition of problem (Penyelesaian Masalah) Logical design (Pseudo code/Flow chart) Programming. Test run the program. Documentation of the program.
Flowchart
Flowchart
Graphical method to plan flow of our programs. Shows programs step-by-step operation. Easy to understand and analyze. Can be used to write organized programs.
Flowchart
Basic shapes:
Indicates beginning and end of flowchart. Once at beginning, once at end. Examples:
START
FINISH
Example:
A=A+B
Reset Ports
Clear D0
Shows alternative program flow based on condition. Represented as diamond shape. Should have 2 arrows, representing TRUE and FALSE program flows. Can be used in ifelse, while, and for situations.
Examples:
D0 = 3?
Port is active?
TRUE
FALSE
TRUE
FALSE
Shows the process of inputting or outputting data. Represented using rhombus. Examples:
Input D0
Used to link large process flows together. Represented using circles, with numbers inside. Numbers indicate connection. Examples:
Example: Connector
START
1
Input D0
D0 = D0 x D1
Input D1 FINISH 1
Once flowchart is complete, write code to implement program. Follow program flow closely. Check and fix problems if necessary.
D0
Input D0 D0 = D0 x D1
Input D1 FINISH
Translation to Assembly
START ORG $1000
Input D0
MOVE.W
#$12,D0
Input D1
MOVE.W
#$34,D1
D0 = D0 x D1
MULU
D1,D0
FINISH
END
Complete Program
START ORG $1000
MOVE.W MOVE.W
MULU
#$12,D0 #$34,D1
D1,D0
END
START
D0 = 0?
FALSE
D1 = D1 + (A0)
FINISH
START
ORG
$1000 #$11,$1100 #$22,$1102 #$33,$1104 #$44,$1106 #$55,$1108 #$66,$110A #$77,$110C #$88,$110E #$99,$1110 #$11,$1112
MOVE.W MOVE.W MOVE.W MOVE.W MOVE.W MOVE.W MOVE.W MOVE.W MOVE.W MOVE.W
MOVEA.L
#$1100,A0
D0 = 10 Clear D1 D0 = 0?
FALSE
D1 = D1 + (A0)
ADDA.L #$2,A0
SUB.B #$1,D0
FINISH
END
Complete Program
START ORG MOVE.W MOVE.W MOVE.W MOVE.W MOVE.W MOVE.W MOVE.W MOVE.W MOVE.W MOVE.W $1000 #$11,$1100 #$22,$1102 #$33,$1104 #$44,$1106 #$55,$1108 #$66,$110A #$77,$110C #$88,$110E #$99,$1110 #$11,$1112
MOVEA.L #$1100,A0 MOVE.B #10,D0 CLR.B D1 LOOP ADD.W ADDA.L SUB.B CMP.B BNE END (A0),D1 #$2,A0 #$1,D0 #$0,D0 LOOP START
Terminologies
Machine code Mnemonic Source File Object Files, List File, Hex file Assembler Single-line assembler Cross Assembler Pseudo-opcode
Machine code
Programming code written in a machine language that can be executed directly by a machine (computer) without any conversion or translation. A low-level code interpreted and converted from high-level source code and understood only by the machine. Machine code is transported to the system processor when a specific task, application or program executes even the smallest process.
Mnemonic
A mnemonic (pronounced "nemonic") is a pattern that can be used as an aid for memorizing information. Most often, this pattern consists of letters or words.
Mnemonic is an abbreviation of the words used in an assembly language program to represent an instruction. Depending on the microprocessor types, for example in Motorola mnemonic is different from Intel Contains the machine language instructions, translated into machine code MOV Move MVI Move Immediate LDA Load Accumulator Directly from Memory
Source code
In computer science - source code is any collection of computer instructions (possibly with comments) written using some human-readable computer language, usually as text The source code of a program is specially designed to facilitate the work of computer programmers, who specify the actions to be performed by a computer mostly by writing source code. The source code is often transformed by a compiler program into low-level machine code understood by the computer
Object Files
Compilers and assemblers create object files containing the generated binary code and data for a source file. Containing object code, meaning relocatable format machine code that is usually not directly executable
List File
A list file is simply a text file that contains a list of other files.
Hex File
The Intel hex (ihex) generally known as hex file, is a format used to store machine language code in hexadecimal form. It is widely used format to store programs to be transferred to microcontrollers, ROM and EEPROM. The compilers convert the programs written in assembly, C etc into corresponding hex files, which are dumped into the controllers using burners/programmers.
Hex File
The microcontroller understands machine language consisting of zeroes and ones. Its difficult rather practically impossible for humans to write codes in zeros and ones. Hence we use some high level languages like C, C++, Java, etc. And later a compiler is used to convert these codes into machine language which are stored in a hex file format. A hex file is a text file with the extension .hex.
Assembler
A computer program which translates from assembly language to an object file or machine language format A program that takes basic computer instructions and converts them into a pattern of bits that the computer's processor can use to perform its basic operations. Some people call these instructions assembler language and others use the term assembly language.
Single-line assembler
single-line mean a program that doesn't assemble an entire file but only one statement. That is generally called "DEBUG.EXE"
WIN XP debug: C:\>debug -a100 117E:0100 rol eax,3 ^ Error 117E:0100 -q
Cross assembler
An assembler that generates machine language for a different type of computer than the one the assembler is running in. It is used to develop programs for computers on a chip or microprocessors used in specialized applications that are either too small or are otherwise incapable of handling the development software. Common methods involve transmitting an exact byte-bybyte copy of the machine code or an ASCII representation of the machine code in a portable format (such as Motorola or Intel hexadecimal) through a compatible interface to the target system for execution.
pseudo-opcode
An assembler directive or pseudo-opcode is a command given to an assembler "directing it to perform operations other than assembling instructions." Sometimes the term pseudo-opcode is reserved for directives that generate object code
Object file (Motorola: S-file). Contains machine code. Links together multiple S-files. Creates single S-file from combined files.
Assembly File #1
Assembly File #2
Assembly File #3
Assembly File #4
ASSEMBLER
Listing File
Object File #1
Object File #2
Object File #3
Object File #4
LINKER
Listing File
Exercise 1:
Assembler Source code Object code Cross Assembler IDE (integrated Development Environment)
ANSWER
Exercise 2
ANSWER
END
Addressing Mode
END CH 3
Assembler
Single-line assembler
Cross-assembler
Pseudo-opcode