Title: Comunicaci
1Comunicación y Gerencia
Fundamentals of Assembly Language
Click To add Subtitle
2Lesson plan
- Review of existing concepts
- Data transfer instructions
- Practice
- Basic arithmetic instructions and
- Repetitive move operations
- Practice
3Review of existing concepts
- Comments
- Directives (page, segment, title)
- Data type (Byte (DB), Word(DW), Doubleword(DD),
String - Some arithmetic operations ADD,SUB,MUL,DIV
4Data transfer instructions
- MOV instruction
- Transfers data referenced by the address of the
second operand to the address of the first
operand - Destination has to have the same length as source
- label MOV register/memory
register/memory/immediate - Example
- MOV F, AX // Move content of AX to the
variable F - MOV CX, D // Move value of D to CX
- MOV ES, AX
- MOV AX, 215
-
5Note
- MOV instruction cant
-
- set the value of the CS and IP registers.
- copy value of one segment register to another
segment register (should copy to general register
first). - MOV ES, DS
- copy immediate value to segment register (should
copy to general register first). - MOV DS, 100
- MOV instruction cant
-
- set the value of the CS and IP registers.
- copy value of one segment register to another
segment register (should copy to general register
first). - MOV ES, DS
- copy immediate value to segment register (should
copy to general register first). - MOV DS, 100
6MOVSB and MOVSW
- MOVSB
- Copy byte at DSSI to ESDI. Update SI and
DI.Algorithm ESDI DSSI - if DF 0 then
- SI SI 1
- DI DI 1
- else
- SI SI - 1
- DI DI - 1
- DF direction flag from the flag register
7MOVSB and MOVSW
- MOVSW
- Copy word at DSSI to ESDI. Update SI and
DI. ESDI DSSI - if DF 0 then
- SI SI 2
- DI DI 2
- else
- SI SI - 2
- DI DI - 2
- DF direction flag from the flag register
8XCHG instruction
- XCHG swap the two data items
- label XCHG register/memory, register/memory
- Example
- MOV AL, 5
- MOV AH, 2
- XCHG AL, AH AL 2, AH 5
- XCHG AL, AH AL 5, AH 2
9LEA instruction
- Load Effective Address. REG address of memory
(offset) - label LEA register/memory
- Example
- LEA AX, m load offset address of m to AX
10Arithmetic instructions
- INC and DEC instruction
- Increasing or decreasing the contents of register
or memory location by 1 - label INC/DEC register/memory
- Flag OF, SF and ZF
- OFis set when an instruction resulted in a carry
into the sign bit of the result. - SF is set if the sign bit of a result is set
- ZF is set if the result is equal to 0.
-
11Arithmetic instructions
- ADD
- label ADD/SUB operand1, operand 2
- operand1 operand 1 operand 2
- Operand 1 register/memory
- Operand 2 register/memory/immediate
12Arithmetic instructions
- SUB
- label SUB operand1, operand 2
- operand1 operand 1 - operand 2
- operand 1 register/memory
- operand 2 register/memory/immediate
13Arithmetic instructions
- MUL operand
- Unsigned multiply. Operand register/memory
14Arithmetic instructions
- IMUL operand
- Signed multiply. Operand register/memory
- Example
- MOV AX, -2
- MOV CX, -3
- IMUL CX AX 6
- CF 0
15Arithmetic instructions
- DIV operand
- Unsigned multiply. Operand register/memory
- when operand is a byteAL AX / operandAH
remainder (modulus) - when operand is a wordDX remainder (modulus)
16Arithmetic instructions
- IDIV operand
- Signed multiply. Operand register/memory
- when operand is a byteAL AX / operandAH
remainder (modulus) - when operand is a wordDX remainder (modulus)
17Practice
- Write a program to convert from Celsius to
Fahrenheit and vice versa - Tc (5/9)(Tf-32)
- Tc censius
- Tf fahrenheit
- (The result may not be accurate due to the
integer division but that is fine)
18Repetitive move instructions
TITLE A04ASM1 (EXE) Move and add operations
--------------------------------------------- STAC
K SEGMENT PARA STACK 'Stack' DW 32
DUP(0) STACK ENDS ------------------------------
---------------- DATASEG SEGMENT PARA 'Data'
STRING1 DB "12345678","" STRING2 DB ?
DATASEG ENDS
19Repetitive move instructions
- CODESEG SEGMENT PARA 'Code'
- MAIN PROC FAR
- MOV AX, dataseg
- MOV DS, AX
- MOV ES, AX
-
- MOV CX, 09 Initialize to move
9 characters - LEA SI, STRING1 Initialize source
index register to offset of string 1 - LEA DI, STRING2 Initialize
destination index register to offset of string 2 -
- BEGINLOOP
- MOV AL,SI Get a current
character from string 1 to AL - MOV DI, AL Move it to the
current character in string 2 - INC SI Move to the next
character in string 1 - INC DI Move to the next
character in string 2 - DEC CX Decrease the count
for loop - JNZ BEGINLOOP Continue to loop
if count is not 0 -
- MOV AH, 09H
20Result
21Repetitive move instructions
- DEC CX
- ZF 1 if CX 0
- JNZ LABEL
- if ZF 0 then jump to the label
22Practice
- Develop an assembly program to
- Define byte items BYTE1 and BYTE2 (Assign any
values for these two variables) - Define a word item WORD3 and WORD30
- Move content of Byte1 to AL
- Add content of Byte2 to AL
- Set DL 42H
- Exchange the content of AL and DL
- Multiply the contents of AL by DL
- Transfer product from AX to WORD3
23Addressing mode
- Register addressing
- E.g ADD AX, BX
- fastest type of operations
- Immediate addressing
- Immediate contains a constant value or an
expression - E.g MOV AX, 0245H
- Direct memory addressing
- One of operand references a memory location and
the other operand references a register - E.G MOV FLDF, AX
24Addressing mode
- Direct-Offset addressing
- use arithmetic instruction to modify an address
- e.g MOV CX, DATAZ2
- Indirect memory addressing
- Use BX and BP, DI and SI within
- e.g. MOV BX, CL
25Addressing mode
- Base Displacement Addressing
- Uses BX, BP and DI, SI and combine with a
displacement to form an effective address - E.g MOV AL,SI2
- Base-Index Addressing
- Combine BX,BP with DI,SI to form effective
address - E.G MOV AL,BXSI
26Addressing mode
- Base-Index Displacement Addressing
- Combine BX, BP and DI, SI and a displacement to
form an effective address - E.g MOV AL,BXSI2
27NEAR and FAR address
- NEAR address
- consists of 16 bit offset portion of an address
- used in real mode
- FAR address
- consists of both the segment and offset portions
in the form of 32 bit segmentoffset
28SEGMENT OVERRIDE PREFIX
- Example
- MOV ESSI2, CL move CL to ESSI2