fundamental of assembly language programming (for microprocessor)
DESCRIPTION
Prima Dewi Purnamasari Microprocessor Electrical Engineering Department Universitas Indonesia. Fundamental of Assembly Language Programming (for Microprocessor). Computer Language. High Level language Pascal, C, C++, Java, etc Low Level Language Assembly Machine Codes - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/1.jpg)
Fundamental of Assembly Language Programming (for Microprocessor)
Prima Dewi PurnamasariMicroprocessor
Electrical Engineering Department Universitas Indonesia
![Page 2: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/2.jpg)
Computer Language
High Level language Pascal, C, C++, Java, etc
Low Level Language Assembly
Machine Codes 010010001010100101010 in binary 1234 FFAB 1234 H in hexadecimal
2 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 3: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/3.jpg)
Why Assembly? Assembly has several features that make it a good
choice many some situations.1. It's fast – Assembly programs are generally
faster than programs created in higher level languages. Often, programmers write speed-essential functions in assembly.
2. It's powerful – You are given unlimited power over your assembly programs. Sometimes, higher level languages have restrictions that make implementing certain things difficult.
3. It's small – Assembly programs are often much smaller than programs written in other languages. This can be very useful if space is an issue.3 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 4: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/4.jpg)
Preparation for Assembly Programming
Basically you will need: Program editor as simple as Notepad Assembler
1. MASM http://www.masm32.com/.2. TASM Made by Borland, a commercial product3. NASM http://sourceforge.net/projects/nasm/
Be careful in writing your programs, because it runs directly on your microprocessor!
4 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 5: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/5.jpg)
Steps to Create a Program
5 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 6: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/6.jpg)
MASM32
6 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 7: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/7.jpg)
TASM
7 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 8: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/8.jpg)
Emulator
an emulator is hardware and/or software that duplicates (or emulates) the functions of a first computer system in a different second computer system, so that the behavior of the second system closely resembles the behavior of the first system.
8 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 9: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/9.jpg)
Emu8086
9 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 10: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/10.jpg)
Individual Assignment
Download and install emu8086 (trial)
http://www.emu8086.com/
Find corresponding tutorial on how to use it (available on the Internet!), self study!
10 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 11: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/11.jpg)
Group assignment
Each group is responsible to bring at minimum 1 laptop (with emu8086 installed) to class every session
11 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 12: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/12.jpg)
Creating an Assembly Language Program
An assembly language program should be written with any text editor and have the extension filename.asm.
The assembler and Linker The assembler program converts a symbolic
source module (file) into a hexadecimal object file The linker program executes as the second part of
ML, reads the object files, created by the assembler program, and links them into a single execution file (.EXE)
12 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 13: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/13.jpg)
13 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 14: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/14.jpg)
Assembly Program Structure
14 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 15: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/15.jpg)
15 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 16: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/16.jpg)
LIST File, generated automatically after program successfully assembled
Machine codes
MemoryAddre
ss
16 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 17: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/17.jpg)
Writing Structure
NEXT: MOV AX, [BX] ; comment
1= label, followed by “:”2= opcode3= operand4= comment, preceded with”;”
1 432
17 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 18: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/18.jpg)
Writing Structure
Each statement in an assembly language program consists of four parts or fields.
The leftmost field is called the label. used to store a symbolic name for the memory
location it represents All labels must begin with a letter or one of
the following special characters: @, $, -, or ?. a label may have any length from 1 to 35
characters The label appears in a program to identify the
name of a memory location for storing data and for other purposes.
18 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 19: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/19.jpg)
The next field to the right is the opcode field. designed to hold the instruction, or opcode the MOV part of the move data instruction is an
example of an opcode Right of the opcode field is the operand field.
contains information used by the opcode the MOV AL,BL instruction has the opcode MOV
and operands AL and BL The comment field, the final field, contains a
comment about the instruction(s). comments always begin with a semicolon (;)
19 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 20: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/20.jpg)
Try it in emulator! Click “View” and look the changes in every menu
list: registers Data Screen Flags etc
20 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 21: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/21.jpg)
Computer Data Formats
Microprocessor (c) Prima Dewi Purnamasari 201121
![Page 22: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/22.jpg)
Computer Data Formats
ASCII and Unicode Data Binary Coded Decimal (BCD) Byte-Sized Data Word-Sized Data Doubleword-Sized Data Real Numbers
Microprocessor (c) Prima Dewi Purnamasari 201122
![Page 23: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/23.jpg)
ASCII Data
American Standard Code for Information Interchange (ASCII) data represent alphanumeric characters in the memory of a computer system (Table 1.7)
The standard ASCII code is a 7-bit code with the eighth and MSB used to hold parity in some systems
ASCII are most often stored in memory using a special directive to the assembler program called define byte(s) or DB
Microprocessor (c) Prima Dewi Purnamasari 201123
![Page 24: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/24.jpg)
Microprocessor (c) Prima Dewi Purnamasari 201124
![Page 25: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/25.jpg)
BCD Data
Binary-Coded Decimal (BCD) information is stored in either packed or unpacked forms
Packed BCD data are stored as two digits per byte
Unpacked BCD data are stored as one digit per byte
The range of a BCD digit extends from 00002 to 10012 or 0-9 decimal
Table 1.9 shows some decimal numbers converted to both packed ad unpacked BCD
Microprocessor (c) Prima Dewi Purnamasari 201125
![Page 26: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/26.jpg)
Microprocessor (c) Prima Dewi Purnamasari 201126
![Page 27: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/27.jpg)
Byte-Sized Data
Byte-size data are stored as unsigned and signed integers
Negative signed numbers are stored in the 2’s complement form Whenever a number is 2’s complement, its sign
changes from negative to positive or positive to negative
See example 1-22, 1-23
Microprocessor (c) Prima Dewi Purnamasari 201127
![Page 28: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/28.jpg)
Microprocessor (c) Prima Dewi Purnamasari 201128
![Page 29: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/29.jpg)
Define bit (DB) directive is used to store 8-bit data in memory
Microprocessor (c) Prima Dewi Purnamasari 2011 29
![Page 30: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/30.jpg)
Word-sized Data
A word (16-bits) is formed with two bytes of data The LSB is always stored in the lowest-numbered
memory location, the MSB in the highest (i.e., little endian format)—used with Intel family of microprocessor
An alternate method (i.e., big endian format) is used with the Motorola family of micro-processors
Microprocessor (c) Prima Dewi Purnamasari 201130
![Page 31: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/31.jpg)
Word-sized Data
Fig 1.11(a) & (b) shows the weight of each bit position in a word of data
Microprocessor (c) Prima Dewi Purnamasari 201131
![Page 32: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/32.jpg)
Microprocessor (c) Prima Dewi Purnamasari 201132
![Page 33: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/33.jpg)
Example 1.25 shows several signed and unsigned word-sized data stored in memory using the assembler program
Note that define word(s) directive or DW causes the assembler to store words in the memory
Microprocessor (c) Prima Dewi Purnamasari 201133
![Page 34: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/34.jpg)
Microprocessor (c) Prima Dewi Purnamasari 201134
![Page 35: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/35.jpg)
Doubleword-sized Data Doubleword-sized data requires four bytes of
memory (32-bit number) Doubleword-sized data appear as a product
after a multiplication and also as a dividend before a division
Fig. 1-12 shows the form used to store doublewords in the memory and the binary weights of each bit position
Microprocessor (c) Prima Dewi Purnamasari 201135
![Page 36: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/36.jpg)
Microprocessor (c) Prima Dewi Purnamasari 201136
![Page 37: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/37.jpg)
To define doubleword-sized data, use assembler directive define doubleword or DD
Microprocessor (c) Prima Dewi Purnamasari 2011 37
![Page 38: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/38.jpg)
Real Numbers
A real number (floating-point number) contains two parts: a mantissa, significant, or fraction and an exponent
Fig. 1-13 and example 1-27 depicts both the 4-byte (single precision) and 8-byte (double precision) forms of real numbers
Microprocessor (c) Prima Dewi Purnamasari 201138
![Page 39: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/39.jpg)
Microprocessor (c) Prima Dewi Purnamasari 201139
![Page 40: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/40.jpg)
The exponent is stored as a biased exponent an exponent of 23 is represented as a biased
exponent of 127+3 or 130 (82H) in the single- precision form or as 1026 (402H) in the double-precision form
Microprocessor (c) Prima Dewi Purnamasari 201140
![Page 41: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/41.jpg)
Microprocessor (c) Prima Dewi Purnamasari 201141
![Page 42: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/42.jpg)
Assembler detail
From chapter 4
Microprocessor (c) Prima Dewi Purnamasari 20114242 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 43: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/43.jpg)
Directives
Indicate how an operand or section of program is to be processed by the assembler
Storing Data in a Memory Segment: DB, DW, DD, SEGMENT, .DATA, ENDS, DUP, ALIGN e.g.: Example 4.12
THIS refers the data as byte or word
43 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 44: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/44.jpg)
Memory is reserved for use in the future by using a question mark (?) as an operand for a DB, DW, or DD directive. when ? is used in place of a numeric or ASCII value,
the assembler sets aside a location and does not initialize it to any specific value
DUP: creates array with or without initial values It is important that word-sized data are placed at
word boundaries and doubleword-sized data are placed at doubleword boundaries. if not, the microprocessor spends additional
time accessing these data types
44 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 45: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/45.jpg)
45
Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 46: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/46.jpg)
EQU, ORG ASSUME
Equate directive (EQU) equates a numeric, ASCII, or label to another label. equates make a program clearer and simplify
debugging EX: TEN EQU 10 …. MOV AL,TEN
The ORG (origin) statement changes the starting offset address of the data or code segments.
At times, the origin of data or the code must be assigned to an absolute offset address with the ORG statement.
ASSUME tells the assembler what names have been chosen for the code, data, extra, and stack segments. Used only with full-segment definition
46 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 47: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/47.jpg)
47
Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 48: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/48.jpg)
PROC and ENDP Indicate start and end of a procedure (subroutine).
they force structure because the procedure is clearly defined
Both the PROC and ENDP directives require a label to indicate the name of the procedure.
RET instruction executed the end of the proc. USES directive indicates which registers are used by
the proc. The assembler automatically save and restore
them using the stack instructions. EX: PRC1 PROC USES AX BX CX Use .LISTALL directive to view all instruction
generated by assembler
48 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 49: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/49.jpg)
49
Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 50: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/50.jpg)
50
Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 51: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/51.jpg)
Memory Organization
The assembler uses two basic formats for developing software: one method uses models; the other uses full-
segment definitions Memory models are unique to MASM. The models are easier to use for simple
tasks. The full-segment definitions offer better
control over the assembly language task and are recommended for complex programs.
51 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 52: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/52.jpg)
Models
There are many models available to the MASM assembler, ranging from tiny to huge.
.MODEL memsize TINY: all software and data fit into 64kb memory segment.
Useful for small programs. assembled as a command (.COM) program
SMALL: one data segment with one code segment for a total of 128kb of memory. assembled as an execute (.EXE) program
Start of segments: .CODE, .DATA, .STACK Start of instructions and load segment registers with
segment addresses: .STARTUP Exit to DOS: .EXIT End of file: END MP selection : .386, .486, .586, .686 ..
52 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 53: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/53.jpg)
53
Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 54: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/54.jpg)
Full Segment Definitions Full-segment definitions are also used with the
Borland and Microsoft C/C++ environments for procedures developed in assembly language
More structured form than the model method Use assume directive before the program begins. The program loader does not automatically
initialize DS and ES. These registers must be loaded in the program
STACK_SEG, DAT_SEG, CODE_SEG, END MAIN
54 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 55: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/55.jpg)
STACK_SEG SEGMENT‘STACK’DW 100H DUP(?)
STACK_SEG ENDS
DATA_SEG SEGMENT‘DATA’LISTA DB 100 DUP(?)LISTB DB 100 DUP(?)
DATA_SEG ENDS
COSE_SEG SEGMENT‘CODE’ASSUME CS:CODE_SEG, DS:DATA_SEG, SS:STACK_SEG
MAIN PROC FARMOV AX, DATA_SEGMOV ES, AXMOV DS, AXCLDMOV SI, OFFSET LISTAMOV DI, OFFSET LISTBMOV CX, 100REP MOVSB
MAIN ENDPCODE_SEG ENDS
END MAIN
55 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 56: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/56.jpg)
Introduction to MOV Instruction
56 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 57: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/57.jpg)
MOV instruction provides a basis for explanation of data-addressing modes
opcode
an opcode, or operation code, tells the microprocessor which operation to perform
Data Addressing Modes
57 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 58: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/58.jpg)
MOV Instruction
MOV instruction perform COPY of a value, either from or to memory or register MOV = COPY MOV ≠ MOVE
58 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 59: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/59.jpg)
MOV BX, CX
► The source register’s contents do not change. the destination register’s contents do change
► The contents of the destination register or destination memory location change for all instructions except the CMP and TEST instructions.
► Note that only the rightmost 16 bits of register EBX change. The MOV BX, CX instruction does not affect the leftmost 16 bits of register EBX59 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 60: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/60.jpg)
Some MOV Variant
MOV AX,BX MOV [BX], AX
[ ] sign represents memory location Destination = memory which has address as in BX
MOV DATA,AX DATA is a name the programmer define in DATA
SEGMENT destination=memory named DATA
MOV AX,0123H a value 0123H is copied to AX register
There are several more, but the above are the fundamental ones 60 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 61: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/61.jpg)
Rules in addressing. DO NOT:
Mix different size of register MOV AX, BL
Perform memory to memory addressing MOV [1234H],DATA
Copy content of one segment register to another MOV DS,ES
Use CS as the destination register MOV CS,1000H
61 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 62: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/62.jpg)
Group Assignment—Due Thursday 22/9
Make a program (altogether in one program, sequentially) Reserve place for data in data segment namely
DATA1 with type word Copy 1234 to AX Copy 0011B to AL Copy 12H to AH Copy AX to DATA1
62 Microprocessor (c) Prima Dewi Purnamasari 2011
![Page 63: Fundamental of Assembly Language Programming (for Microprocessor)](https://reader031.vdocuments.net/reader031/viewer/2022020717/5681401c550346895dab7176/html5/thumbnails/63.jpg)
The report
Write the program in emulator Compile it. Run the program in emulator. (single step).
Analyze the effect on the registers and memory for each line of code
Written report should be made as comprehensive as it can be (greater score for better report)
The main part of your report would be:1. Print of program (source code), provide sufficient
comment2. Print of LISTING file3. Program analysis 63 Microprocessor (c) Prima Dewi Purnamasari 2011