SlideShare a Scribd company logo
assembly language programming organization of IBM PC chapter 9 part-2(decimal input,output)
Batch (014)
assembly language programming organization of IBM PC chapter 9 part-2(decimal input,output)
Topic:
Decimal Input and Output
Group member:
M NABEEL (14093122-014)
TAYYAB SAEED (14093122-015)
NASEER AHMAD (14093122-016)
AQEEL HAIDER (14093122-017)
MIR HAMZA MAJEED (14093122-018)
HAMZA TAJ (14093122-018)
Decimal Input and Output
 Computer represent every thing in binary.
 But it is convenient for user to represent input
and output in decimal.
 If we input 21543 character string then it must
to converted internally.
 Conversely on output the binary contents of R/M
must be converted to decimal equivalent before
being printed.
Decimal input
 Convert a string of ASCII digits to the binary
representation of decimal equivalent
 For input we repeatedly multiply AX by 10
Algorithm (First version):
Total=0
Read an ASCII
REPEAT
convert character to number
Total=total*10+value
Read a character
Until character is carriage return
Cont..
Example: input of 123
Total =0
Read ‘1’
Convert ‘1’ to 1
Total=10*0 +1=1
Read ‘2’
Convert ‘2’ to 2
Total=10*1 +2=12
Read ‘3’
Convert ‘3’ to 3
Total=10*12 +3=123
Cont..
Range: -32768 to 32767
Optional sign followed by string of digits &
carriage return
Outside ‘0’ to ‘9’
jumps to new line and ask for input again
Cont..
Algorithm(second version):
total=0
Negative=false
Read a character
Case character of
• ‘-’: negative=true
read a character
• ‘+’: read a character
End_case
Repeat
If character is not between ‘0’ to ‘9’
Then
Go to beginning
Cont..
Else
Convert character to binary value
Total=10*total+value
End_if
Read a character
Until character is carriage return
If negative =true
Then
total=-total
Cont..
Program(source code):
INDEC PROC
;READ NUMBER IN RANGE -32768 TO 32767
PUSH BX
PUSH CX
PUSH DX
@BEGIN:
;total =0
XOR BX,BX ;BX hold total
;negative =false
Cont..
XOR CX,CX ;CX hold sign
;read char
MOV AH,1
INT 21H
;case char of
CMP AL,'-' ;minus sign
JE @MINUS ;yes,set sign
CMP AL,'+' ;plus sign
JE @PLUS ;yes,get another char
Cont..
JMP @REPEAT2 ;start processing char
@MINUS: MOV CX,1
@PLUS: INT 21H
;end case
@REPEAT2:
;if char. is between '0' and '9'
CMP AL,'0' ;char >='0'?
JNGE @NOT_DIGIT ;illegal char.
Cont..
CMP AL,'9' ;char<='9' ?
JNLE @NOT_DIGIT
;then convert char to digit
AND AX,000FH
PUSH AX ;save number
;total =total *10 +digit
MOV AX,10
MUL BX
POP BX ;retrieve number
ADD BX,AX ;total =total *10 +digit
Cont..
;read char
MOV AH,1
INT 21H
CMP AL,0DH ;CR
JNE @REPEAT2 ;no keep going
;until CR
MOV AX,BX ;store number in AX
;if negative
OR CX,CX ;negative number
Cont..
Jz @EXIT ;no,exit
;then
NEG AX ;yes,negate
;end if
@EXIT: ;retrieve registers
POP DX
POP CX
POP BX
RET
Cont..
;here if illegal char entered
@NOT_DIGIT:
MOV AH,2
MOV DL,0DH
INT 21H
MOV DL,0AH
INT 21H
JMP @BEGIN
INDEC ENDP
Cont..
Output:
Input Overflow
 AX:FFFFh
 In decimal:65535
 Range:-32768 to 32767
 Anything out of range called input overflow
 For example:
 Input:32769
 Total=327690
Cont..
Algorithm:
total=0
Negative=false
Read a character
Case character of
• ‘-’: negative=true
read a character
• ‘+’: read a character
Cont..
End_case
Repeat
If character is not between ‘0’ to ‘9’
Then
Go to beginning
Else
Convert character to binary value
Total=10*total
Cont..
If overflow
Then
go to beginning
Else
Total =total*10 +value
If overflow
Then
go to beginning
Cont..
End_if
End_if
End_if
Read a character
Until character is carriage return
If negative =true
Then
total=-total
Cont..
Code:
;total =total *10 +digit
MOV AX,10
MUL BX
CMP DX,0
JNE @NOT_DIGIT
POP BX
ADD BX,AX
JC @NOT_DIGIT
Cont..
Output:
Algorithm for Decimal Output:
 If AX < 0 /*AX holds output value */
 THEN
 Print a minus sign
 Replace AX by its twos complement
 End_IF
 Get the digits in AX’s decimal representation
 Convert these digits into characters and print them
Decimal Output
Cont..
To see what line 6 entitles, suppose the contents of AX,
expressed in decimal is 24168. To get the digits in decimal
representation , we can proceed as follows,
 Divide 24618 by 10, Quotient= 2461, remainder=8
 Divide 2461 by 10, Quotient= 246, remainder=1
 Divide 246 by 10 , Quotient=24, remainder=6
 Divide 24 by 10, Quotient=2, remainder=4
 Divide 2 by 10, Quotient=0, remainder=2
Cont..
LINE 6:
Cout =0 /*will count decimal digit */
REPEAT
divide quotient by 10
Push remainder on the stack
Count= count +1
UNTILL
Quotient=0
Cont..
LINE 7:
FOR count times DO
Pop a digit from the stack
Convert it to a character
Output the character
END_FOR
Cont..
Program Listing PMG9_1.ASM
.MODEL SMALL
.STACK 100H
.CODE
OUTDEC PROC
;prints AX as a signed decimal integer
;input: AX
;output: none
PUSH AX ;save registers
PUSH BX
PUSH CX
PUSH DX
Cont..
;if AX < 0
OR AX,AX ;AX < 0?
JGE @END_IF1 ;NO >0
;then
PUSH AX ; save number
MOV DL,’-’ ;get ‘-’
MOV AH,2 ;print character function
INT 21H ;print ‘-’
POP AX ;get Ax back
NEG AX ;AX= -AX
@END_IF1:
Cont..
;get decimal digits
XOR CX,CX ;CX counts digits
MOV BX,10D ;BX has divisor
@REPEAT1:
XOR DX,DX ;prepare high word of dividend
DIV BX ;AX=quotient, DX=remainder
PUSH DX ;save remainder on stack
INC CX ;count = count +1
;until
OR AX,AX ;quotient = 0?
JNE @REPEAT ;no, keep going
Cont..
;convert digits to character and print
MOV AH,2 ;print character function
;for count time do
@PRINT_LOOP
POP DX ;digit in DL
OR DL,30H ;convert to character
INT 21H ;print digit
;end_for
POP DX ; restore registers
POP CX
POP BX
POP AX
OUTDEC ENDP
assembly language programming organization of IBM PC chapter 9 part-2(decimal input,output)
Ad

Recommended

PDF
chapter 7 Logic, shift and rotate instructions
warda aziz
 
PDF
Chap 8 The stack and introduction to procedures & Chapter 9 multiplication an...
warda aziz
 
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Bilal Amjad
 
PPTX
Prefix, Infix and Post-fix Notations
Afaq Mansoor Khan
 
PDF
Chapter 6 Flow control Instructions
warda aziz
 
PPTX
Multiplication & division instructions microprocessor 8086
University of Gujrat, Pakistan
 
PDF
Introduction to ibm pc assembly language
warda aziz
 
PPTX
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
Bilal Amjad
 
PPTX
Binary and hex input/output (in 8086 assembuly langyage)
Bilal Amjad
 
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...
Bilal Amjad
 
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Bilal Amjad
 
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Bilal Amjad
 
PDF
Assembly Langauge Chap 1
warda aziz
 
PPTX
Ppt on Linked list,stack,queue
Srajan Shukla
 
PDF
Chapter 5The proessor status and the FLAGS registers
warda aziz
 
PDF
Organization of the ibm personal computers
warda aziz
 
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Bilal Amjad
 
PPTX
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Bilal Amjad
 
PPTX
Pointers in C
Vijayananda Ratnam Ch
 
PPSX
Stack
Seema Sharma
 
PPTX
language , grammar and automata
ElakkiyaS11
 
PDF
assembly language programming and organization of IBM PC" by YTHA YU
Education
 
PDF
Representation of numbers and characters
warda aziz
 
PPTX
bubble sorting of an array in 8086 assembly language
Bilal Amjad
 
PPT
Assembly Language Lecture 5
Motaz Saad
 
PPSX
C lecture 4 nested loops and jumping statements slideshare
Gagan Deep
 
PDF
Assembly language (coal)
Hareem Aslam
 
PDF
Taller Ensambladores
Christian Morales
 
PPT
Al2ed chapter11
Abdullelah Al-Fahad
 

More Related Content

What's hot (20)

PPTX
Binary and hex input/output (in 8086 assembuly langyage)
Bilal Amjad
 
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...
Bilal Amjad
 
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Bilal Amjad
 
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Bilal Amjad
 
PDF
Assembly Langauge Chap 1
warda aziz
 
PPTX
Ppt on Linked list,stack,queue
Srajan Shukla
 
PDF
Chapter 5The proessor status and the FLAGS registers
warda aziz
 
PDF
Organization of the ibm personal computers
warda aziz
 
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Bilal Amjad
 
PPTX
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Bilal Amjad
 
PPTX
Pointers in C
Vijayananda Ratnam Ch
 
PPSX
Stack
Seema Sharma
 
PPTX
language , grammar and automata
ElakkiyaS11
 
PDF
assembly language programming and organization of IBM PC" by YTHA YU
Education
 
PDF
Representation of numbers and characters
warda aziz
 
PPTX
bubble sorting of an array in 8086 assembly language
Bilal Amjad
 
PPT
Assembly Language Lecture 5
Motaz Saad
 
PPSX
C lecture 4 nested loops and jumping statements slideshare
Gagan Deep
 
PDF
Assembly language (coal)
Hareem Aslam
 
Binary and hex input/output (in 8086 assembuly langyage)
Bilal Amjad
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...
Bilal Amjad
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Bilal Amjad
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Bilal Amjad
 
Assembly Langauge Chap 1
warda aziz
 
Ppt on Linked list,stack,queue
Srajan Shukla
 
Chapter 5The proessor status and the FLAGS registers
warda aziz
 
Organization of the ibm personal computers
warda aziz
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Bilal Amjad
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Bilal Amjad
 
Pointers in C
Vijayananda Ratnam Ch
 
language , grammar and automata
ElakkiyaS11
 
assembly language programming and organization of IBM PC" by YTHA YU
Education
 
Representation of numbers and characters
warda aziz
 
bubble sorting of an array in 8086 assembly language
Bilal Amjad
 
Assembly Language Lecture 5
Motaz Saad
 
C lecture 4 nested loops and jumping statements slideshare
Gagan Deep
 
Assembly language (coal)
Hareem Aslam
 

Similar to assembly language programming organization of IBM PC chapter 9 part-2(decimal input,output) (20)

PDF
Taller Ensambladores
Christian Morales
 
PPT
Al2ed chapter11
Abdullelah Al-Fahad
 
PPTX
L12_ COA_COmputer architecurte and organization
sambhuduttan
 
PPTX
[ASM]Lab7
Nora Youssef
 
PDF
Taller practico emu8086_galarraga
Fabricio Galárraga
 
PPSX
Assembly language programming
Gaurav Takrani
 
PPT
Instruction set of 8086
Tirumalesh Nizampatnam
 
PPT
Unit 2 8086 Instruction set.ppt notes good
SahilSingh866567
 
PPT
8086 instruction set
mengistu ketema
 
PPT
1344 Alp Of 8086
techbed
 
PDF
Exp 03
madzflores
 
DOCX
Assembly language
bryle12
 
PDF
Instructionsetof8086 180224060745(3)
AmitPaliwal20
 
DOCX
Instruction set of 8086
Vijay Kumar
 
PDF
6 c control statements branching &amp; jumping
MomenMostafa
 
PPTX
Module 2 (1).pptx
Dr. Thippeswamy S.
 
PPTX
Mod-2.pptx
Dr. Thippeswamy S.
 
PPTX
Instruction 4.pptx
HebaEng
 
PDF
8086 instructions
Ravi Anand
 
PDF
Microprocessor 8086-lab-mannual
yeshwant gadave
 
Taller Ensambladores
Christian Morales
 
Al2ed chapter11
Abdullelah Al-Fahad
 
L12_ COA_COmputer architecurte and organization
sambhuduttan
 
[ASM]Lab7
Nora Youssef
 
Taller practico emu8086_galarraga
Fabricio Galárraga
 
Assembly language programming
Gaurav Takrani
 
Instruction set of 8086
Tirumalesh Nizampatnam
 
Unit 2 8086 Instruction set.ppt notes good
SahilSingh866567
 
8086 instruction set
mengistu ketema
 
1344 Alp Of 8086
techbed
 
Exp 03
madzflores
 
Assembly language
bryle12
 
Instructionsetof8086 180224060745(3)
AmitPaliwal20
 
Instruction set of 8086
Vijay Kumar
 
6 c control statements branching &amp; jumping
MomenMostafa
 
Module 2 (1).pptx
Dr. Thippeswamy S.
 
Mod-2.pptx
Dr. Thippeswamy S.
 
Instruction 4.pptx
HebaEng
 
8086 instructions
Ravi Anand
 
Microprocessor 8086-lab-mannual
yeshwant gadave
 
Ad

More from Bilal Amjad (11)

PDF
IoT Based Smart Energy Meter using Raspberry Pi and Arduino
Bilal Amjad
 
PDF
Power Systems analysis with MATPOWER and Simscape Electrical (MATLAB/Simulink)
Bilal Amjad
 
PDF
Solar Radiation monthly prediction and forecasting using Machine Learning tec...
Bilal Amjad
 
PDF
Big Data in Smart Grid
Bilal Amjad
 
PPTX
Flexibility of Power System (Sources of flexibility & flexibility markets)
Bilal Amjad
 
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Bilal Amjad
 
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...
Bilal Amjad
 
PPTX
Limit of complex number
Bilal Amjad
 
PPTX
simple combinational lock
Bilal Amjad
 
PPTX
4-bit camparator
Bilal Amjad
 
PPTX
Orthogonal trajectories
Bilal Amjad
 
IoT Based Smart Energy Meter using Raspberry Pi and Arduino
Bilal Amjad
 
Power Systems analysis with MATPOWER and Simscape Electrical (MATLAB/Simulink)
Bilal Amjad
 
Solar Radiation monthly prediction and forecasting using Machine Learning tec...
Bilal Amjad
 
Big Data in Smart Grid
Bilal Amjad
 
Flexibility of Power System (Sources of flexibility & flexibility markets)
Bilal Amjad
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Bilal Amjad
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...
Bilal Amjad
 
Limit of complex number
Bilal Amjad
 
simple combinational lock
Bilal Amjad
 
4-bit camparator
Bilal Amjad
 
Orthogonal trajectories
Bilal Amjad
 
Ad

Recently uploaded (20)

PDF
Validating a Citizen Observatories enabling Platform by completing a Citizen ...
Diego López-de-Ipiña González-de-Artaza
 
PPTX
Bharatiya Antariksh Hackathon 2025 Idea Submission PPT.pptx
AsadShad4
 
PDF
FSE-Journal-First-Automated code editing with search-generate-modify.pdf
cl144
 
PDF
Rapid Prototyping for XR: Lecture 3 - Video and Paper Prototyping
Mark Billinghurst
 
PPSX
OOPS Concepts in Python and Exception Handling
Dr. A. B. Shinde
 
PDF
Plant Control_EST_85520-01_en_AllChanges_20220127.pdf
DarshanaChathuranga4
 
PPTX
How to Un-Obsolete Your Legacy Keypad Design
Epec Engineered Technologies
 
PDF
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Mark Billinghurst
 
PPTX
Stability of IBR Dominated Grids - IEEE PEDG 2025 - short.pptx
ssuser307730
 
PDF
Designing for Tomorrow – Architecture’s Role in the Sustainability Movement
BIM Services
 
PDF
輪読会資料_Miipher and Miipher2 .
NABLAS株式会社
 
PPTX
Comparison of Flexible and Rigid Pavements in Bangladesh
Arifur Rahman
 
PPTX
CST413 KTU S7 CSE Machine Learning Introduction Parameter Estimation MLE MAP ...
resming1
 
PPT
SF 9_Unit 1.ppt software engineering ppt
AmarrKannthh
 
PPTX
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
moonsony54
 
PPTX
WHO And BIS std- for water quality .pptx
dhanashree78
 
PPTX
Introduction to Python Programming Language
merlinjohnsy
 
PDF
تقرير عن التحليل الديناميكي لتدفق الهواء حول جناح.pdf
محمد قصص فتوتة
 
PDF
NFPA 10 - Estandar para extintores de incendios portatiles (ed.22 ENG).pdf
Oscar Orozco
 
PDF
Rapid Prototyping for XR: Lecture 6 - AI for Prototyping and Research Directi...
Mark Billinghurst
 
Validating a Citizen Observatories enabling Platform by completing a Citizen ...
Diego López-de-Ipiña González-de-Artaza
 
Bharatiya Antariksh Hackathon 2025 Idea Submission PPT.pptx
AsadShad4
 
FSE-Journal-First-Automated code editing with search-generate-modify.pdf
cl144
 
Rapid Prototyping for XR: Lecture 3 - Video and Paper Prototyping
Mark Billinghurst
 
OOPS Concepts in Python and Exception Handling
Dr. A. B. Shinde
 
Plant Control_EST_85520-01_en_AllChanges_20220127.pdf
DarshanaChathuranga4
 
How to Un-Obsolete Your Legacy Keypad Design
Epec Engineered Technologies
 
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Mark Billinghurst
 
Stability of IBR Dominated Grids - IEEE PEDG 2025 - short.pptx
ssuser307730
 
Designing for Tomorrow – Architecture’s Role in the Sustainability Movement
BIM Services
 
輪読会資料_Miipher and Miipher2 .
NABLAS株式会社
 
Comparison of Flexible and Rigid Pavements in Bangladesh
Arifur Rahman
 
CST413 KTU S7 CSE Machine Learning Introduction Parameter Estimation MLE MAP ...
resming1
 
SF 9_Unit 1.ppt software engineering ppt
AmarrKannthh
 
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
moonsony54
 
WHO And BIS std- for water quality .pptx
dhanashree78
 
Introduction to Python Programming Language
merlinjohnsy
 
تقرير عن التحليل الديناميكي لتدفق الهواء حول جناح.pdf
محمد قصص فتوتة
 
NFPA 10 - Estandar para extintores de incendios portatiles (ed.22 ENG).pdf
Oscar Orozco
 
Rapid Prototyping for XR: Lecture 6 - AI for Prototyping and Research Directi...
Mark Billinghurst
 

assembly language programming organization of IBM PC chapter 9 part-2(decimal input,output)

  • 4. Topic: Decimal Input and Output Group member: M NABEEL (14093122-014) TAYYAB SAEED (14093122-015) NASEER AHMAD (14093122-016) AQEEL HAIDER (14093122-017) MIR HAMZA MAJEED (14093122-018) HAMZA TAJ (14093122-018)
  • 5. Decimal Input and Output  Computer represent every thing in binary.  But it is convenient for user to represent input and output in decimal.  If we input 21543 character string then it must to converted internally.  Conversely on output the binary contents of R/M must be converted to decimal equivalent before being printed.
  • 6. Decimal input  Convert a string of ASCII digits to the binary representation of decimal equivalent  For input we repeatedly multiply AX by 10 Algorithm (First version): Total=0 Read an ASCII REPEAT convert character to number Total=total*10+value Read a character Until character is carriage return
  • 7. Cont.. Example: input of 123 Total =0 Read ‘1’ Convert ‘1’ to 1 Total=10*0 +1=1 Read ‘2’ Convert ‘2’ to 2 Total=10*1 +2=12 Read ‘3’ Convert ‘3’ to 3 Total=10*12 +3=123
  • 8. Cont.. Range: -32768 to 32767 Optional sign followed by string of digits & carriage return Outside ‘0’ to ‘9’ jumps to new line and ask for input again
  • 9. Cont.. Algorithm(second version): total=0 Negative=false Read a character Case character of • ‘-’: negative=true read a character • ‘+’: read a character End_case Repeat If character is not between ‘0’ to ‘9’ Then Go to beginning
  • 10. Cont.. Else Convert character to binary value Total=10*total+value End_if Read a character Until character is carriage return If negative =true Then total=-total
  • 11. Cont.. Program(source code): INDEC PROC ;READ NUMBER IN RANGE -32768 TO 32767 PUSH BX PUSH CX PUSH DX @BEGIN: ;total =0 XOR BX,BX ;BX hold total ;negative =false
  • 12. Cont.. XOR CX,CX ;CX hold sign ;read char MOV AH,1 INT 21H ;case char of CMP AL,'-' ;minus sign JE @MINUS ;yes,set sign CMP AL,'+' ;plus sign JE @PLUS ;yes,get another char
  • 13. Cont.. JMP @REPEAT2 ;start processing char @MINUS: MOV CX,1 @PLUS: INT 21H ;end case @REPEAT2: ;if char. is between '0' and '9' CMP AL,'0' ;char >='0'? JNGE @NOT_DIGIT ;illegal char.
  • 14. Cont.. CMP AL,'9' ;char<='9' ? JNLE @NOT_DIGIT ;then convert char to digit AND AX,000FH PUSH AX ;save number ;total =total *10 +digit MOV AX,10 MUL BX POP BX ;retrieve number ADD BX,AX ;total =total *10 +digit
  • 15. Cont.. ;read char MOV AH,1 INT 21H CMP AL,0DH ;CR JNE @REPEAT2 ;no keep going ;until CR MOV AX,BX ;store number in AX ;if negative OR CX,CX ;negative number
  • 16. Cont.. Jz @EXIT ;no,exit ;then NEG AX ;yes,negate ;end if @EXIT: ;retrieve registers POP DX POP CX POP BX RET
  • 17. Cont.. ;here if illegal char entered @NOT_DIGIT: MOV AH,2 MOV DL,0DH INT 21H MOV DL,0AH INT 21H JMP @BEGIN INDEC ENDP
  • 19. Input Overflow  AX:FFFFh  In decimal:65535  Range:-32768 to 32767  Anything out of range called input overflow  For example:  Input:32769  Total=327690
  • 20. Cont.. Algorithm: total=0 Negative=false Read a character Case character of • ‘-’: negative=true read a character • ‘+’: read a character
  • 21. Cont.. End_case Repeat If character is not between ‘0’ to ‘9’ Then Go to beginning Else Convert character to binary value Total=10*total
  • 22. Cont.. If overflow Then go to beginning Else Total =total*10 +value If overflow Then go to beginning
  • 23. Cont.. End_if End_if End_if Read a character Until character is carriage return If negative =true Then total=-total
  • 24. Cont.. Code: ;total =total *10 +digit MOV AX,10 MUL BX CMP DX,0 JNE @NOT_DIGIT POP BX ADD BX,AX JC @NOT_DIGIT
  • 26. Algorithm for Decimal Output:  If AX < 0 /*AX holds output value */  THEN  Print a minus sign  Replace AX by its twos complement  End_IF  Get the digits in AX’s decimal representation  Convert these digits into characters and print them Decimal Output
  • 27. Cont.. To see what line 6 entitles, suppose the contents of AX, expressed in decimal is 24168. To get the digits in decimal representation , we can proceed as follows,  Divide 24618 by 10, Quotient= 2461, remainder=8  Divide 2461 by 10, Quotient= 246, remainder=1  Divide 246 by 10 , Quotient=24, remainder=6  Divide 24 by 10, Quotient=2, remainder=4  Divide 2 by 10, Quotient=0, remainder=2
  • 28. Cont.. LINE 6: Cout =0 /*will count decimal digit */ REPEAT divide quotient by 10 Push remainder on the stack Count= count +1 UNTILL Quotient=0
  • 29. Cont.. LINE 7: FOR count times DO Pop a digit from the stack Convert it to a character Output the character END_FOR
  • 30. Cont.. Program Listing PMG9_1.ASM .MODEL SMALL .STACK 100H .CODE OUTDEC PROC ;prints AX as a signed decimal integer ;input: AX ;output: none PUSH AX ;save registers PUSH BX PUSH CX PUSH DX
  • 31. Cont.. ;if AX < 0 OR AX,AX ;AX < 0? JGE @END_IF1 ;NO >0 ;then PUSH AX ; save number MOV DL,’-’ ;get ‘-’ MOV AH,2 ;print character function INT 21H ;print ‘-’ POP AX ;get Ax back NEG AX ;AX= -AX @END_IF1:
  • 32. Cont.. ;get decimal digits XOR CX,CX ;CX counts digits MOV BX,10D ;BX has divisor @REPEAT1: XOR DX,DX ;prepare high word of dividend DIV BX ;AX=quotient, DX=remainder PUSH DX ;save remainder on stack INC CX ;count = count +1 ;until OR AX,AX ;quotient = 0? JNE @REPEAT ;no, keep going
  • 33. Cont.. ;convert digits to character and print MOV AH,2 ;print character function ;for count time do @PRINT_LOOP POP DX ;digit in DL OR DL,30H ;convert to character INT 21H ;print digit ;end_for POP DX ; restore registers POP CX POP BX POP AX OUTDEC ENDP