SlideShare una empresa de Scribd logo
1 de 60
Descargar para leer sin conexión
Microprocessor Based Systems
Spring 2013
Department of Electrical Engineering
University of Gujrat
2
IBM
CHARACTER
DISPLAY
TITLE IBM CHARACTER DISPLAY
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
MOVAH, 2 ; display char function
MOVCX, 256 ; no. of chars to display
MOVDL, 0 ; DL has ASCII code of null char
PRINT_LOOP:
INT 21h ; display a char
INC DL ; increment ASCII code
DEC CX ; decrement counter
JNZ PRINT_LOOP ; keep going if CX not 0
; DOS exit
MOVAH, 4CH
INT 21H
MAIN ENDP
END MAIN
3
Label
4
5
IBM Character Display
• IBM.ASM
6
Conditional Jumps
• Jxxx destination_label
• In IBM.ASM, the CPU executes JNZ
PRINT_LOOP by inspecting ZF.
• If ZF = 0, control transfers to PRINT_LOOP
• If ZF = 1, it goes on to execute MOV AH, 4CH
• Jump instructions themselves do not affect
the flags.
7
Range of a conditional jump
• destination_label must precede the jump
instruction by no more than 126 bytes, or
follow it by no more than 127 bytes.
8
jumps
Conditional
jumps
Signed Jumps
Unsigned
Jumps
Single Flag
Jumps
Unconditional
jumps
9
The CMP (compare) Instruction
• CMP destination, source
• CMP is just like SUB, except that destination is
not changed.
• CMP AX, BX ; AX = 7FFFh, BX = 0001h
JG BELOW ; AX – BX = 7FFEh
• The jump condition for JG is satisfied because
ZF = SF = OF = 0, so control transfers to label
BELOW.
10
Interpreting the Conditional Jumps
• CMP AX, BX
JG BELOW
• If AX is greater than BX (in a signed sense), then
JG (jump if greater than) transfers to BELOW.
• DEC AX
JL THERE
• If the contents of AX, in a signed sense, is less
than 0, control transfers to THERE.
11
12
Jumps Based on Specific Flags
13
Jumps Based on Unsigned
Comparisons
14
Jumps Based on Signed Comparisons
Signed Versus Unsigned Jumps
• CMP AX, BX ; AX = 7FFFh, BX = 8000h
JA BELOW
• 7FFFh > 8000h in a signed sense, the program
does not jump to BELOW.
• 7FFFh < 8000h in an unsigned sense, and we
are using the unsigned jump JA.
15
Suppose AX and BX contain signed numbers.
Write some code to put the biggest one in CX.
MOV CX, AX ; put AX in CX
CMP BX, CX ; is BX bigger?
JLE NEXT ; no, go on
MOV CX, BX ; yes, put BX in CX
NEXT:
16
The JMP Instruction
• JMP destination
• JMP can be used to get around the range
restriction of a conditional jump.
17
Unconditional Jump
TOP:
; body of the loop
DEC CX ; decrement counter
JNZ TOP ; keep looping if CX > 0
MOV AX, BX
; the loop body contains so many instructions
that label TOP is out of range for JNZ
(more than 126 bytes before JMP TOP)
18
Unconditional Jump
TOP:
; body of the loop
DEC CX ; decrement counter
JNZ BOTTOM ; keep looping if CX > 0
JMP EXIT
BOTTOM:
JMP TOP
EXIT:
MOV AX, BX
19
High level language constructs
20
IF-THEN
IF condition is true
THEN
execute true-branch statements
END_IF
21
Replace the number in AX by its
absolute value.
IF AX < 0
THEN
replace AX by –AX
END_IF
22
Replace the number in AX by its
absolute value.
; if AX < 0
CMP AX, 0 ; AX < 0 ?
JNL END_IF ; no, exit
; then
NEG AX ; yes, change sign
END IF:
23
IF-THEN-ELSE
IF condition is true
THEN
execute true-branch statements
ELSE
execute false-branch statements
END_IF
24
Suppose AL and BL contain extended ASCII
characters. Display the one that comes first
in the character sequence.
IF AL <= BL
THEN
display the character in AL
ELSE
display the character in BL
END_IF
25
Suppose AL and BL contain extended ASCII
characters. Display the one that comes first
in the character sequence.
MOV AH, 2 ; prepare to display
; if AL <= BL
CMP AL, BL ; AL <= BL?
JNBE ELSE_ ; no, display char in BL
; then ; AL <= BL
MOV DL, AL ; move char to be displayed
JMP DISPLAY ; go to display
ELSE_: ; BL < AL
MOV DL, BL
DISPLAY:
INT 21h ; display it
END_IF
26
ELSE is a
reserved word
Needed to skip false
branch (not needed in
high level language)
CASE
CASE expression
value 1 : statements_1
value 2 : statements_2
.
.
.
value n : statements_n
END_CASE
27
If AX contains a negative number, put –1 in
BX; if AX contains 0, put 0 in BX, if AX
contains a positive number , put 1 in BX.
CASE AX
<0 : put –1 in BX
=0 : put 0 in BX
>0 : put 1 in BX
END_CASE
28
If AX contains a negative number, put –1 in
BX; if AX contains 0, put 0 in BX, if AX
contains a positive number , put 1 in BX.
; case AX
CMP AX, 0 ; test AX
JL NEGATIVE ; AX < 0
JE ZERO ; AX = 0
JG POSITIVE ; AX > 0
NEGATIVE:
MOV BX, -1 ; put -1 in BX
JMP END_CASE ; and exit
ZERO:
MOV BX, 0 ; put -0in BX
JMP END_CASE ; and exit
POSITIVE:
MOV BX, 1 ; put 1 in BX
END_CASE:
29
Only one cmp is
needed as jump
instructions don’t
affect the flags
If AL contains 1 or 3, display “o”;
If AL contains 2 or 4, display “e”.
CASE AL
1, 3 : display “o”
2, 4 : display “e”
END_CASE
30
If AL contains 1 or 3, display “o”;
If AL contains 2 or 4, display “e”.
; case AL
; 1,3 :
CMP AL, 1 ; AL = 1?
JE ODD ; yes, display ‘o’
CMP AL ,3 ; AL = 3?
JE ODD ; yes, display ‘o’
; 2,4 :
CMP AL, 2 ; AL = 2?
JE EVEN ; yes, display ‘e’
CMP AL, 4 ; AL = 4?
JE EVEN ; yes, display ‘e’
JMP END_CASE ; not 1..4
31
If AL contains 1 or 3, display “o”;
If AL contains 2 or 4, display “e”.
ODD: ; display ‘o’
MOV DL, ‘o’ ; get ‘o’
JMP DISPLAY ; go to display
EVEN: ; display ‘e’
MOV DL, ‘e’ ; get ‘e’
DISPLAY:
MOV AH, 2
INT 21H ; display char
END_CASE:
32
Branches with Compound Conditions
• Some times the branching in an IF or CASE
takes from;
• condition_1 AND condition_2
or
condition_1 OR condition_2
33
AND Conditions
• condition_1 AND condition_2
• An AND condition is true if and only if
condition_1 and condition_2 are both true.
• If either condition is false, then the whole
thing is false.
34
Read a character, and if it’s an
uppercase letter, display it.
Read a character (into AL)
IF (‘A’ <= character) and (character <= ‘Z’)
THEN
display character
END_IF
35
Read a character, and if it’s an
uppercase letter, display it.
; read a character
MOV AH, 1 ; prepare to read
INT 21H ; char in AL
; if (‘A’ <= char) and (char >= ‘Z’)
CMP AL, ‘A’ ; char >= ‘A’?
JNGE END_IF ; no, exit
CMP AL, ‘Z’ ; char <= ‘Z’?
JNLE END_IF ; no, exit
; then display char
MOV DL, AL ; get char
MOV AH, 2 ; prepare to display
INT 21H ; display char
END_IF:
36
OR Conditions
• condition_1 OR condition_2
• condition_1 OR condition_2 is true if at least
one of the conditions is true.
• It is only false when both conditions are false.
37
Read a character, and if it is “y” or “Y”, display
it; otherwise, terminate the program.
Read a character (into AL)
IF (character = ‘y’) or (character = ‘Y’)
THEN
display it
ELSE
terminate the program
END_IF
38
Read a character, and if it is “y” or “Y”, display
it; otherwise, terminate the program.
; read a character
MOV AH, 1 ; prepare to read
INT 21H ; char in AL
; if (character = ‘y’) or (character = ‘Y’)
CMP AL, ‘y’ ; char = ‘y’?
JE THEN ; yes, go to display it
CMP AL, ‘Y’ ; char = ‘Y’?
JE THEN ; yes, go to display it
JMP ELSE_ ; no, terminate
39
Read a character, and if it is “y” or “Y”, display
it; otherwise, terminate the program.
THEN:
MOV AH, 2 ; prepare to display
MOV DL, AL ; get char
INT 21H ; display it
JMP END_IF ; end exit
ELSE_:
MOV AH, 4CH
INT 21H ; DOS exit
END_IF:
40
Looping Structures
• A loop is a sequence of instructions that is
repeated .
• The number of times to repeat may be known
in advance
or
• Depend on some condition
41
FOR LOOP
Loop statements are repeated a known number
of times;
FOR loop_count times DO
statements
END_FOR
42
The LOOP instruction
• LOOP destination_label
; initialize CX to loop_count
TOP:
; body of the loop
LOOP TOP
43
The LOOP instruction
• The counter for the loop is the register CX which
is initialized to loop_count.
• Execution of the LOOP instruction causes CX to be
decremented automatically.
• If CX is not 0, control transfers to
destination_label.
• If CX = 0, the next instruction after LOOP is done.
• destination_label must precede the LOOP
instruction by no more than 126 bytes.
44
Write a count-controlled loop to
display a row of 80 stars.
FOR 80 times DO
display ‘*’
END_FOR
45
Write a count-controlled loop to
display a row of 80 stars.
MOV CX, 80 ; number of stars to display
MOV AH, 2 ; display character function
MOV DL, ‘*’ ; character to display
TOP:
INT 21h ; display a star
LOOP TOP ; repeat 80 times
46
The instruction JCXZ (jump if CX is zero)
• JCXZ destination_label
JCXZ SKIP
TOP:
; body of the loop
LOOP TOP
SKIP:
47
The instruction JCXZ (jump if CX is zero)
• If CX contains 0 when the loop is entered, the
LOOP instruction causes CX to be
decremented to FFFFh, and the loop is then
executed FFFFh = 65535 more times!
48
WHILE condition DO
statements
END_WHILE
_______________________________________
REPEAT
statements
UNTIL condition
WHILE LOOP and REPEAT LOOP
49
Statements
Condition
Statements
Condition
Write some code to count the number
of characters in an input line.
Initialize count to 0
read a character
WHILE character <> carriage_return DO
count = count + 1
read a character
END_WHILE
50
Write some code to count the number
of characters in an input line.
MOV DX, 0 ; DX counts characters
MOV AH, 1 ; prepare to read
INT 21H ; character in AL
WHILE_:
CMP AL, 0DH ; CR?
JE END_WHILE ; yes, exit
INC DX ; not CR, increment count
INT 21H ; read a character
JMP WHILE_ ; loop back
END_WHILE_:
51
Write some code to read characters
until a blank is read.
REPEAT
read a character
UNTIL character is a blank
______________________________________________
MOV AH, 1 ; prepare to read
REPEAT:
INT 21H ; char in AL
; until
CMP AL, ‘ ‘ ; a blank?
JNE REPEAT ; no, keep reading
52
Programming with High-Level Structures
• CAP.ASM
Type a line of text:
THE QUICK BROWN FOX JUMPED.
First capital = B Last capital = X
53
If no capital letter entered,
display
“No capital letter entered”
Read and process a line of text
Read a character
WHILE character is not a carriage return DO
IF character is a capital letter (‘A’ <= character AND character <= ‘Z’)
THEN
IF character precedes first capital
THEN first capital = character
END IF
IF character follows last capital
THEN last capital = character
END IF
END IF
Read a character
END_WHILE
54
Display the results
IF no capitals were typed,
THEN
display “No capitals”
ELSE
display first capital and last capital
END_IF
55
ASCII
Character
Table
FIRST
LAST
CAP.ASM
1(4)
TITLE FIRST AND LAST CAPITALS
.MODEL SMALL
.STACK 100H
.DATA
PROMPT DB 'Type a line of text', 0DH,
0AH, '$'
NOCAP_MSG DB 0DH, 0AH, 'No capitals $'
CAP_MSG DB 0DH, 0AH, 'First capital =
'
FIRST DB '['
DB ' Last capital = '
LAST DB '@ $'
.CODE
MAIN PROC
; initialize DS
MOV AX, @DATA
MOV DS, AX
; display opening message
MOV AH, 9 ; display string function
LEA DX, PROMPT ; get opening message
INT 21H ; display it
; read and process a line of text
MOV AH, 1 ; read char function
INT 21H ; char in AL
WHILE_:
; while character is not a carriage return do
CMP AL, 0DH ; CR?
JE END_WHILE ; yes, exit
; if character is a capital letter
CMP AL, 'A' ; char >= 'A'?
JNGE END_IF ; not a capital letter
CMP AL, 'Z' ; chat <= 'Z'?
JNLE END_IF ; not a capital letter
; then
CAP.ASM
2(4)
CAP.ASM
3(4)
; if character precedes first capital
CMP AL, FIRST ; char < first capital?
JNL CHECK_LAST ; no, >=
; then first capital = character
MOV FIRST, AL ; FIRST = char
; end_if
CHECK_LAST:
; if character follows last capital
CMP AL, LAST ; char > last capital?
JNG END_IF ; no, <=
; then last capital = character
MOV LAST, AL ; LAST = char
; end_if
END_IF:
; read a character
INT 21H ; char in AL
JMP WHILE_ ; repeat loop
END_WHILE:
; display results
MOVAH, 9 ; display string function
; if no capitals were typed
CMPFIRST, '['; first = '['
JNECAPS ; no, display results
; then
LEADX, NOCAP_MSG ; no capitals
JMPDISPLAY
CAPS:
LEADX, CAP_MSG ; capitals
DISPLAY:
INT21H ; display message
; end_if
; dos exit
MOVAH, 4CH
INT21H
MAIN ENDP
END MAIN
CAP.ASM
4(4)

Más contenido relacionado

La actualidad más candente

Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...Bilal Amjad
 
Chapter 5The proessor status and the FLAGS registers
Chapter 5The proessor status and the FLAGS registersChapter 5The proessor status and the FLAGS registers
Chapter 5The proessor status and the FLAGS registerswarda aziz
 
Introduction to ibm pc assembly language
Introduction to ibm pc assembly languageIntroduction to ibm pc assembly language
Introduction to ibm pc assembly languagewarda aziz
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Bilal Amjad
 
Representation of numbers and characters
Representation of numbers and charactersRepresentation of numbers and characters
Representation of numbers and characterswarda aziz
 
8086 instructions
8086 instructions8086 instructions
8086 instructionsRavi Anand
 
Jumps in Assembly Language.
Jumps in Assembly Language.Jumps in Assembly Language.
Jumps in Assembly Language.NA000000
 
Multiplication & division instructions microprocessor 8086
Multiplication & division instructions microprocessor 8086Multiplication & division instructions microprocessor 8086
Multiplication & division instructions microprocessor 8086University of Gujrat, Pakistan
 
Assembly language
Assembly language Assembly language
Assembly language Usama ahmad
 
Assembly Language Lecture 5
Assembly Language Lecture 5Assembly Language Lecture 5
Assembly Language Lecture 5Motaz Saad
 
Assembly Langauge Chap 1
Assembly Langauge Chap 1Assembly Langauge Chap 1
Assembly Langauge Chap 1warda aziz
 
assembly language programming organization of IBM PC chapter 9 part-2(decimal...
assembly language programming organization of IBM PC chapter 9 part-2(decimal...assembly language programming organization of IBM PC chapter 9 part-2(decimal...
assembly language programming organization of IBM PC chapter 9 part-2(decimal...Bilal Amjad
 
assembly language programming and organization of IBM PC" by YTHA YU
assembly language programming and organization of IBM PC" by YTHA YUassembly language programming and organization of IBM PC" by YTHA YU
assembly language programming and organization of IBM PC" by YTHA YUEducation
 
Organization of the ibm personal computers
Organization of the ibm personal computersOrganization of the ibm personal computers
Organization of the ibm personal computerswarda aziz
 
Assembly language 8086 intermediate
Assembly language 8086 intermediateAssembly language 8086 intermediate
Assembly language 8086 intermediateJohn Cutajar
 
Assembly language (coal)
Assembly language (coal)Assembly language (coal)
Assembly language (coal)Hareem Aslam
 
Logical instructions (and, or, xor, not, test)
Logical instructions (and, or, xor, not, test)Logical instructions (and, or, xor, not, test)
Logical instructions (and, or, xor, not, test)Irfan Anjum
 
Assembly Language Lecture 4
Assembly Language Lecture 4Assembly Language Lecture 4
Assembly Language Lecture 4Motaz Saad
 

La actualidad más candente (20)

Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
 
Chapter 5The proessor status and the FLAGS registers
Chapter 5The proessor status and the FLAGS registersChapter 5The proessor status and the FLAGS registers
Chapter 5The proessor status and the FLAGS registers
 
Introduction to ibm pc assembly language
Introduction to ibm pc assembly languageIntroduction to ibm pc assembly language
Introduction to ibm pc assembly language
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
 
Representation of numbers and characters
Representation of numbers and charactersRepresentation of numbers and characters
Representation of numbers and characters
 
Assembly 8086
Assembly 8086Assembly 8086
Assembly 8086
 
8086 instructions
8086 instructions8086 instructions
8086 instructions
 
Jumps in Assembly Language.
Jumps in Assembly Language.Jumps in Assembly Language.
Jumps in Assembly Language.
 
Multiplication & division instructions microprocessor 8086
Multiplication & division instructions microprocessor 8086Multiplication & division instructions microprocessor 8086
Multiplication & division instructions microprocessor 8086
 
Assembly language
Assembly language Assembly language
Assembly language
 
Assembly Language Lecture 5
Assembly Language Lecture 5Assembly Language Lecture 5
Assembly Language Lecture 5
 
Assembly Langauge Chap 1
Assembly Langauge Chap 1Assembly Langauge Chap 1
Assembly Langauge Chap 1
 
assembly language programming organization of IBM PC chapter 9 part-2(decimal...
assembly language programming organization of IBM PC chapter 9 part-2(decimal...assembly language programming organization of IBM PC chapter 9 part-2(decimal...
assembly language programming organization of IBM PC chapter 9 part-2(decimal...
 
assembly language programming and organization of IBM PC" by YTHA YU
assembly language programming and organization of IBM PC" by YTHA YUassembly language programming and organization of IBM PC" by YTHA YU
assembly language programming and organization of IBM PC" by YTHA YU
 
axi protocol
axi protocolaxi protocol
axi protocol
 
Organization of the ibm personal computers
Organization of the ibm personal computersOrganization of the ibm personal computers
Organization of the ibm personal computers
 
Assembly language 8086 intermediate
Assembly language 8086 intermediateAssembly language 8086 intermediate
Assembly language 8086 intermediate
 
Assembly language (coal)
Assembly language (coal)Assembly language (coal)
Assembly language (coal)
 
Logical instructions (and, or, xor, not, test)
Logical instructions (and, or, xor, not, test)Logical instructions (and, or, xor, not, test)
Logical instructions (and, or, xor, not, test)
 
Assembly Language Lecture 4
Assembly Language Lecture 4Assembly Language Lecture 4
Assembly Language Lecture 4
 

Destacado

Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...Bilal Amjad
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Bilal Amjad
 
Assembly Language Lecture 2
Assembly Language Lecture 2Assembly Language Lecture 2
Assembly Language Lecture 2Motaz Saad
 
Assembly Language Basics
Assembly Language BasicsAssembly Language Basics
Assembly Language BasicsEducation Front
 
Assembly language programming(unit 4)
Assembly language programming(unit 4)Assembly language programming(unit 4)
Assembly language programming(unit 4)Ashim Saha
 
Chapter 3
Chapter 3Chapter 3
Chapter 3asguna
 
Chapter 4
Chapter 4Chapter 4
Chapter 4asguna
 
8086 microprocessor-architecture-120207111857-phpapp01
8086 microprocessor-architecture-120207111857-phpapp018086 microprocessor-architecture-120207111857-phpapp01
8086 microprocessor-architecture-120207111857-phpapp01jemimajerome
 
Matlab 1
Matlab 1Matlab 1
Matlab 1asguna
 
Matlab 2
Matlab 2Matlab 2
Matlab 2asguna
 
Matlab 3
Matlab 3Matlab 3
Matlab 3asguna
 
Coal 1 - introduction to assembly programming in Assembly Programming
Coal 1 - introduction to assembly programming in Assembly ProgrammingCoal 1 - introduction to assembly programming in Assembly Programming
Coal 1 - introduction to assembly programming in Assembly ProgrammingMuhammad Taqi Hassan Bukhari
 
bubble sorting of an array in 8086 assembly language
bubble sorting of an array in 8086 assembly languagebubble sorting of an array in 8086 assembly language
bubble sorting of an array in 8086 assembly languageBilal Amjad
 
Unit2 control unit
Unit2 control unitUnit2 control unit
Unit2 control unitAshim Saha
 
8086 assembly language
8086 assembly language8086 assembly language
8086 assembly languageMir Majid
 

Destacado (20)

Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
 
Processor Basics
Processor BasicsProcessor Basics
Processor Basics
 
Assembly Language Lecture 2
Assembly Language Lecture 2Assembly Language Lecture 2
Assembly Language Lecture 2
 
Assembly Language Basics
Assembly Language BasicsAssembly Language Basics
Assembly Language Basics
 
Assembly language programming(unit 4)
Assembly language programming(unit 4)Assembly language programming(unit 4)
Assembly language programming(unit 4)
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
8086 microprocessor-architecture-120207111857-phpapp01
8086 microprocessor-architecture-120207111857-phpapp018086 microprocessor-architecture-120207111857-phpapp01
8086 microprocessor-architecture-120207111857-phpapp01
 
Matlab 1
Matlab 1Matlab 1
Matlab 1
 
Matlab 2
Matlab 2Matlab 2
Matlab 2
 
Matlab 3
Matlab 3Matlab 3
Matlab 3
 
Coal 2 - concepts in Assembly Programming
Coal 2 - concepts in Assembly ProgrammingCoal 2 - concepts in Assembly Programming
Coal 2 - concepts in Assembly Programming
 
Coal 1 - introduction to assembly programming in Assembly Programming
Coal 1 - introduction to assembly programming in Assembly ProgrammingCoal 1 - introduction to assembly programming in Assembly Programming
Coal 1 - introduction to assembly programming in Assembly Programming
 
bubble sorting of an array in 8086 assembly language
bubble sorting of an array in 8086 assembly languagebubble sorting of an array in 8086 assembly language
bubble sorting of an array in 8086 assembly language
 
Conditional jump
Conditional jumpConditional jump
Conditional jump
 
Kleene's theorem
Kleene's theoremKleene's theorem
Kleene's theorem
 
Unit2 control unit
Unit2 control unitUnit2 control unit
Unit2 control unit
 
8086 assembly language
8086 assembly language8086 assembly language
8086 assembly language
 

Similar a Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control Instructions,)

Loop instruction, controlling the flow of progam
Loop instruction, controlling the flow of progamLoop instruction, controlling the flow of progam
Loop instruction, controlling the flow of progamDr. Girish GS
 
Intel codetable
Intel codetableIntel codetable
Intel codetableJ R7
 
1344 Alp Of 8086
1344 Alp Of 80861344 Alp Of 8086
1344 Alp Of 8086techbed
 
Taller practico emu8086_galarraga
Taller practico emu8086_galarragaTaller practico emu8086_galarraga
Taller practico emu8086_galarragaFabricio Galárraga
 
Assembly Complete 8086 Instruction Set
Assembly Complete 8086 Instruction SetAssembly Complete 8086 Instruction Set
Assembly Complete 8086 Instruction SetDarian Pruitt
 
Assembly lab up to 6 up (1)
Assembly lab up to 6 up (1)Assembly lab up to 6 up (1)
Assembly lab up to 6 up (1)ilias ahmed
 
Assembly language 8086
Assembly language 8086Assembly language 8086
Assembly language 8086John Cutajar
 
Assembly language
Assembly languageAssembly language
Assembly languagebryle12
 
Microprocessor.pptx
Microprocessor.pptxMicroprocessor.pptx
Microprocessor.pptxNishatNishu5
 

Similar a Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control Instructions,) (20)

Loop instruction, controlling the flow of progam
Loop instruction, controlling the flow of progamLoop instruction, controlling the flow of progam
Loop instruction, controlling the flow of progam
 
Chapt 06
Chapt 06Chapt 06
Chapt 06
 
Chapt 06
Chapt 06Chapt 06
Chapt 06
 
[ASM]Lab5
[ASM]Lab5[ASM]Lab5
[ASM]Lab5
 
Al2ed chapter7
Al2ed chapter7Al2ed chapter7
Al2ed chapter7
 
Intel codetable
Intel codetableIntel codetable
Intel codetable
 
1344 Alp Of 8086
1344 Alp Of 80861344 Alp Of 8086
1344 Alp Of 8086
 
Flag control
Flag controlFlag control
Flag control
 
Taller practico emu8086_galarraga
Taller practico emu8086_galarragaTaller practico emu8086_galarraga
Taller practico emu8086_galarraga
 
[ASM]Lab7
[ASM]Lab7[ASM]Lab7
[ASM]Lab7
 
Assembly language programs
Assembly language programsAssembly language programs
Assembly language programs
 
Taller Ensambladores
Taller EnsambladoresTaller Ensambladores
Taller Ensambladores
 
Assembly Complete 8086 Instruction Set
Assembly Complete 8086 Instruction SetAssembly Complete 8086 Instruction Set
Assembly Complete 8086 Instruction Set
 
Assembly lab up to 6 up (1)
Assembly lab up to 6 up (1)Assembly lab up to 6 up (1)
Assembly lab up to 6 up (1)
 
Assignment on alp
Assignment on alpAssignment on alp
Assignment on alp
 
Assembly language 8086
Assembly language 8086Assembly language 8086
Assembly language 8086
 
Assembly language
Assembly languageAssembly language
Assembly language
 
8086 instruction set
8086  instruction set8086  instruction set
8086 instruction set
 
Al2ed chapter8
Al2ed chapter8Al2ed chapter8
Al2ed chapter8
 
Microprocessor.pptx
Microprocessor.pptxMicroprocessor.pptx
Microprocessor.pptx
 

Más de Bilal Amjad

IoT Based Smart Energy Meter using Raspberry Pi and Arduino
IoT Based Smart Energy Meter using Raspberry Pi and Arduino IoT Based Smart Energy Meter using Raspberry Pi and Arduino
IoT Based Smart Energy Meter using Raspberry Pi and Arduino Bilal Amjad
 
Power Systems analysis with MATPOWER and Simscape Electrical (MATLAB/Simulink)
Power Systems analysis with MATPOWER and Simscape Electrical (MATLAB/Simulink) Power Systems analysis with MATPOWER and Simscape Electrical (MATLAB/Simulink)
Power Systems analysis with MATPOWER and Simscape Electrical (MATLAB/Simulink) Bilal Amjad
 
Solar Radiation monthly prediction and forecasting using Machine Learning tec...
Solar Radiation monthly prediction and forecasting using Machine Learning tec...Solar Radiation monthly prediction and forecasting using Machine Learning tec...
Solar Radiation monthly prediction and forecasting using Machine Learning tec...Bilal Amjad
 
Big Data in Smart Grid
Big Data in Smart GridBig Data in Smart Grid
Big Data in Smart GridBilal Amjad
 
Flexibility of Power System (Sources of flexibility & flexibility markets)
Flexibility of Power System (Sources of flexibility & flexibility markets)Flexibility of Power System (Sources of flexibility & flexibility markets)
Flexibility of Power System (Sources of flexibility & flexibility markets)Bilal Amjad
 
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...Bilal Amjad
 
Limit of complex number
Limit of complex numberLimit of complex number
Limit of complex numberBilal Amjad
 
simple combinational lock
simple combinational locksimple combinational lock
simple combinational lockBilal Amjad
 
4-bit camparator
4-bit camparator4-bit camparator
4-bit camparatorBilal Amjad
 
Orthogonal trajectories
Orthogonal trajectoriesOrthogonal trajectories
Orthogonal trajectoriesBilal Amjad
 

Más de Bilal Amjad (10)

IoT Based Smart Energy Meter using Raspberry Pi and Arduino
IoT Based Smart Energy Meter using Raspberry Pi and Arduino IoT Based Smart Energy Meter using Raspberry Pi and Arduino
IoT Based Smart Energy Meter using Raspberry Pi and Arduino
 
Power Systems analysis with MATPOWER and Simscape Electrical (MATLAB/Simulink)
Power Systems analysis with MATPOWER and Simscape Electrical (MATLAB/Simulink) Power Systems analysis with MATPOWER and Simscape Electrical (MATLAB/Simulink)
Power Systems analysis with MATPOWER and Simscape Electrical (MATLAB/Simulink)
 
Solar Radiation monthly prediction and forecasting using Machine Learning tec...
Solar Radiation monthly prediction and forecasting using Machine Learning tec...Solar Radiation monthly prediction and forecasting using Machine Learning tec...
Solar Radiation monthly prediction and forecasting using Machine Learning tec...
 
Big Data in Smart Grid
Big Data in Smart GridBig Data in Smart Grid
Big Data in Smart Grid
 
Flexibility of Power System (Sources of flexibility & flexibility markets)
Flexibility of Power System (Sources of flexibility & flexibility markets)Flexibility of Power System (Sources of flexibility & flexibility markets)
Flexibility of Power System (Sources of flexibility & flexibility markets)
 
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
 
Limit of complex number
Limit of complex numberLimit of complex number
Limit of complex number
 
simple combinational lock
simple combinational locksimple combinational lock
simple combinational lock
 
4-bit camparator
4-bit camparator4-bit camparator
4-bit camparator
 
Orthogonal trajectories
Orthogonal trajectoriesOrthogonal trajectories
Orthogonal trajectories
 

Último

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdfSuman Jyoti
 

Último (20)

Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 

Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control Instructions,)

  • 1. Microprocessor Based Systems Spring 2013 Department of Electrical Engineering University of Gujrat
  • 2. 2
  • 3. IBM CHARACTER DISPLAY TITLE IBM CHARACTER DISPLAY .MODEL SMALL .STACK 100H .CODE MAIN PROC MOVAH, 2 ; display char function MOVCX, 256 ; no. of chars to display MOVDL, 0 ; DL has ASCII code of null char PRINT_LOOP: INT 21h ; display a char INC DL ; increment ASCII code DEC CX ; decrement counter JNZ PRINT_LOOP ; keep going if CX not 0 ; DOS exit MOVAH, 4CH INT 21H MAIN ENDP END MAIN 3 Label
  • 4. 4
  • 5. 5
  • 7. Conditional Jumps • Jxxx destination_label • In IBM.ASM, the CPU executes JNZ PRINT_LOOP by inspecting ZF. • If ZF = 0, control transfers to PRINT_LOOP • If ZF = 1, it goes on to execute MOV AH, 4CH • Jump instructions themselves do not affect the flags. 7
  • 8. Range of a conditional jump • destination_label must precede the jump instruction by no more than 126 bytes, or follow it by no more than 127 bytes. 8
  • 10. The CMP (compare) Instruction • CMP destination, source • CMP is just like SUB, except that destination is not changed. • CMP AX, BX ; AX = 7FFFh, BX = 0001h JG BELOW ; AX – BX = 7FFEh • The jump condition for JG is satisfied because ZF = SF = OF = 0, so control transfers to label BELOW. 10
  • 11. Interpreting the Conditional Jumps • CMP AX, BX JG BELOW • If AX is greater than BX (in a signed sense), then JG (jump if greater than) transfers to BELOW. • DEC AX JL THERE • If the contents of AX, in a signed sense, is less than 0, control transfers to THERE. 11
  • 12. 12 Jumps Based on Specific Flags
  • 13. 13 Jumps Based on Unsigned Comparisons
  • 14. 14 Jumps Based on Signed Comparisons
  • 15. Signed Versus Unsigned Jumps • CMP AX, BX ; AX = 7FFFh, BX = 8000h JA BELOW • 7FFFh > 8000h in a signed sense, the program does not jump to BELOW. • 7FFFh < 8000h in an unsigned sense, and we are using the unsigned jump JA. 15
  • 16. Suppose AX and BX contain signed numbers. Write some code to put the biggest one in CX. MOV CX, AX ; put AX in CX CMP BX, CX ; is BX bigger? JLE NEXT ; no, go on MOV CX, BX ; yes, put BX in CX NEXT: 16
  • 17. The JMP Instruction • JMP destination • JMP can be used to get around the range restriction of a conditional jump. 17
  • 18. Unconditional Jump TOP: ; body of the loop DEC CX ; decrement counter JNZ TOP ; keep looping if CX > 0 MOV AX, BX ; the loop body contains so many instructions that label TOP is out of range for JNZ (more than 126 bytes before JMP TOP) 18
  • 19. Unconditional Jump TOP: ; body of the loop DEC CX ; decrement counter JNZ BOTTOM ; keep looping if CX > 0 JMP EXIT BOTTOM: JMP TOP EXIT: MOV AX, BX 19
  • 20. High level language constructs 20
  • 21. IF-THEN IF condition is true THEN execute true-branch statements END_IF 21
  • 22. Replace the number in AX by its absolute value. IF AX < 0 THEN replace AX by –AX END_IF 22
  • 23. Replace the number in AX by its absolute value. ; if AX < 0 CMP AX, 0 ; AX < 0 ? JNL END_IF ; no, exit ; then NEG AX ; yes, change sign END IF: 23
  • 24. IF-THEN-ELSE IF condition is true THEN execute true-branch statements ELSE execute false-branch statements END_IF 24
  • 25. Suppose AL and BL contain extended ASCII characters. Display the one that comes first in the character sequence. IF AL <= BL THEN display the character in AL ELSE display the character in BL END_IF 25
  • 26. Suppose AL and BL contain extended ASCII characters. Display the one that comes first in the character sequence. MOV AH, 2 ; prepare to display ; if AL <= BL CMP AL, BL ; AL <= BL? JNBE ELSE_ ; no, display char in BL ; then ; AL <= BL MOV DL, AL ; move char to be displayed JMP DISPLAY ; go to display ELSE_: ; BL < AL MOV DL, BL DISPLAY: INT 21h ; display it END_IF 26 ELSE is a reserved word Needed to skip false branch (not needed in high level language)
  • 27. CASE CASE expression value 1 : statements_1 value 2 : statements_2 . . . value n : statements_n END_CASE 27
  • 28. If AX contains a negative number, put –1 in BX; if AX contains 0, put 0 in BX, if AX contains a positive number , put 1 in BX. CASE AX <0 : put –1 in BX =0 : put 0 in BX >0 : put 1 in BX END_CASE 28
  • 29. If AX contains a negative number, put –1 in BX; if AX contains 0, put 0 in BX, if AX contains a positive number , put 1 in BX. ; case AX CMP AX, 0 ; test AX JL NEGATIVE ; AX < 0 JE ZERO ; AX = 0 JG POSITIVE ; AX > 0 NEGATIVE: MOV BX, -1 ; put -1 in BX JMP END_CASE ; and exit ZERO: MOV BX, 0 ; put -0in BX JMP END_CASE ; and exit POSITIVE: MOV BX, 1 ; put 1 in BX END_CASE: 29 Only one cmp is needed as jump instructions don’t affect the flags
  • 30. If AL contains 1 or 3, display “o”; If AL contains 2 or 4, display “e”. CASE AL 1, 3 : display “o” 2, 4 : display “e” END_CASE 30
  • 31. If AL contains 1 or 3, display “o”; If AL contains 2 or 4, display “e”. ; case AL ; 1,3 : CMP AL, 1 ; AL = 1? JE ODD ; yes, display ‘o’ CMP AL ,3 ; AL = 3? JE ODD ; yes, display ‘o’ ; 2,4 : CMP AL, 2 ; AL = 2? JE EVEN ; yes, display ‘e’ CMP AL, 4 ; AL = 4? JE EVEN ; yes, display ‘e’ JMP END_CASE ; not 1..4 31
  • 32. If AL contains 1 or 3, display “o”; If AL contains 2 or 4, display “e”. ODD: ; display ‘o’ MOV DL, ‘o’ ; get ‘o’ JMP DISPLAY ; go to display EVEN: ; display ‘e’ MOV DL, ‘e’ ; get ‘e’ DISPLAY: MOV AH, 2 INT 21H ; display char END_CASE: 32
  • 33. Branches with Compound Conditions • Some times the branching in an IF or CASE takes from; • condition_1 AND condition_2 or condition_1 OR condition_2 33
  • 34. AND Conditions • condition_1 AND condition_2 • An AND condition is true if and only if condition_1 and condition_2 are both true. • If either condition is false, then the whole thing is false. 34
  • 35. Read a character, and if it’s an uppercase letter, display it. Read a character (into AL) IF (‘A’ <= character) and (character <= ‘Z’) THEN display character END_IF 35
  • 36. Read a character, and if it’s an uppercase letter, display it. ; read a character MOV AH, 1 ; prepare to read INT 21H ; char in AL ; if (‘A’ <= char) and (char >= ‘Z’) CMP AL, ‘A’ ; char >= ‘A’? JNGE END_IF ; no, exit CMP AL, ‘Z’ ; char <= ‘Z’? JNLE END_IF ; no, exit ; then display char MOV DL, AL ; get char MOV AH, 2 ; prepare to display INT 21H ; display char END_IF: 36
  • 37. OR Conditions • condition_1 OR condition_2 • condition_1 OR condition_2 is true if at least one of the conditions is true. • It is only false when both conditions are false. 37
  • 38. Read a character, and if it is “y” or “Y”, display it; otherwise, terminate the program. Read a character (into AL) IF (character = ‘y’) or (character = ‘Y’) THEN display it ELSE terminate the program END_IF 38
  • 39. Read a character, and if it is “y” or “Y”, display it; otherwise, terminate the program. ; read a character MOV AH, 1 ; prepare to read INT 21H ; char in AL ; if (character = ‘y’) or (character = ‘Y’) CMP AL, ‘y’ ; char = ‘y’? JE THEN ; yes, go to display it CMP AL, ‘Y’ ; char = ‘Y’? JE THEN ; yes, go to display it JMP ELSE_ ; no, terminate 39
  • 40. Read a character, and if it is “y” or “Y”, display it; otherwise, terminate the program. THEN: MOV AH, 2 ; prepare to display MOV DL, AL ; get char INT 21H ; display it JMP END_IF ; end exit ELSE_: MOV AH, 4CH INT 21H ; DOS exit END_IF: 40
  • 41. Looping Structures • A loop is a sequence of instructions that is repeated . • The number of times to repeat may be known in advance or • Depend on some condition 41
  • 42. FOR LOOP Loop statements are repeated a known number of times; FOR loop_count times DO statements END_FOR 42
  • 43. The LOOP instruction • LOOP destination_label ; initialize CX to loop_count TOP: ; body of the loop LOOP TOP 43
  • 44. The LOOP instruction • The counter for the loop is the register CX which is initialized to loop_count. • Execution of the LOOP instruction causes CX to be decremented automatically. • If CX is not 0, control transfers to destination_label. • If CX = 0, the next instruction after LOOP is done. • destination_label must precede the LOOP instruction by no more than 126 bytes. 44
  • 45. Write a count-controlled loop to display a row of 80 stars. FOR 80 times DO display ‘*’ END_FOR 45
  • 46. Write a count-controlled loop to display a row of 80 stars. MOV CX, 80 ; number of stars to display MOV AH, 2 ; display character function MOV DL, ‘*’ ; character to display TOP: INT 21h ; display a star LOOP TOP ; repeat 80 times 46
  • 47. The instruction JCXZ (jump if CX is zero) • JCXZ destination_label JCXZ SKIP TOP: ; body of the loop LOOP TOP SKIP: 47
  • 48. The instruction JCXZ (jump if CX is zero) • If CX contains 0 when the loop is entered, the LOOP instruction causes CX to be decremented to FFFFh, and the loop is then executed FFFFh = 65535 more times! 48
  • 49. WHILE condition DO statements END_WHILE _______________________________________ REPEAT statements UNTIL condition WHILE LOOP and REPEAT LOOP 49 Statements Condition Statements Condition
  • 50. Write some code to count the number of characters in an input line. Initialize count to 0 read a character WHILE character <> carriage_return DO count = count + 1 read a character END_WHILE 50
  • 51. Write some code to count the number of characters in an input line. MOV DX, 0 ; DX counts characters MOV AH, 1 ; prepare to read INT 21H ; character in AL WHILE_: CMP AL, 0DH ; CR? JE END_WHILE ; yes, exit INC DX ; not CR, increment count INT 21H ; read a character JMP WHILE_ ; loop back END_WHILE_: 51
  • 52. Write some code to read characters until a blank is read. REPEAT read a character UNTIL character is a blank ______________________________________________ MOV AH, 1 ; prepare to read REPEAT: INT 21H ; char in AL ; until CMP AL, ‘ ‘ ; a blank? JNE REPEAT ; no, keep reading 52
  • 53. Programming with High-Level Structures • CAP.ASM Type a line of text: THE QUICK BROWN FOX JUMPED. First capital = B Last capital = X 53 If no capital letter entered, display “No capital letter entered”
  • 54. Read and process a line of text Read a character WHILE character is not a carriage return DO IF character is a capital letter (‘A’ <= character AND character <= ‘Z’) THEN IF character precedes first capital THEN first capital = character END IF IF character follows last capital THEN last capital = character END IF END IF Read a character END_WHILE 54
  • 55. Display the results IF no capitals were typed, THEN display “No capitals” ELSE display first capital and last capital END_IF 55
  • 57. CAP.ASM 1(4) TITLE FIRST AND LAST CAPITALS .MODEL SMALL .STACK 100H .DATA PROMPT DB 'Type a line of text', 0DH, 0AH, '$' NOCAP_MSG DB 0DH, 0AH, 'No capitals $' CAP_MSG DB 0DH, 0AH, 'First capital = ' FIRST DB '[' DB ' Last capital = ' LAST DB '@ $' .CODE MAIN PROC ; initialize DS MOV AX, @DATA MOV DS, AX
  • 58. ; display opening message MOV AH, 9 ; display string function LEA DX, PROMPT ; get opening message INT 21H ; display it ; read and process a line of text MOV AH, 1 ; read char function INT 21H ; char in AL WHILE_: ; while character is not a carriage return do CMP AL, 0DH ; CR? JE END_WHILE ; yes, exit ; if character is a capital letter CMP AL, 'A' ; char >= 'A'? JNGE END_IF ; not a capital letter CMP AL, 'Z' ; chat <= 'Z'? JNLE END_IF ; not a capital letter ; then CAP.ASM 2(4)
  • 59. CAP.ASM 3(4) ; if character precedes first capital CMP AL, FIRST ; char < first capital? JNL CHECK_LAST ; no, >= ; then first capital = character MOV FIRST, AL ; FIRST = char ; end_if CHECK_LAST: ; if character follows last capital CMP AL, LAST ; char > last capital? JNG END_IF ; no, <= ; then last capital = character MOV LAST, AL ; LAST = char ; end_if END_IF: ; read a character INT 21H ; char in AL JMP WHILE_ ; repeat loop END_WHILE:
  • 60. ; display results MOVAH, 9 ; display string function ; if no capitals were typed CMPFIRST, '['; first = '[' JNECAPS ; no, display results ; then LEADX, NOCAP_MSG ; no capitals JMPDISPLAY CAPS: LEADX, CAP_MSG ; capitals DISPLAY: INT21H ; display message ; end_if ; dos exit MOVAH, 4CH INT21H MAIN ENDP END MAIN CAP.ASM 4(4)