SlideShare a Scribd company logo
1 of 34
Batch (014)
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)

More Related Content

What's hot

Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...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
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...Bilal Amjad
 
Assembly Langauge Chap 1
Assembly Langauge Chap 1Assembly Langauge Chap 1
Assembly Langauge Chap 1warda aziz
 
Organization of the ibm personal computers
Organization of the ibm personal computersOrganization of the ibm personal computers
Organization of the ibm personal computerswarda aziz
 
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
 
Solution manual of assembly language programming and organization of the ibm ...
Solution manual of assembly language programming and organization of the ibm ...Solution manual of assembly language programming and organization of the ibm ...
Solution manual of assembly language programming and organization of the ibm ...Tayeen Ahmed
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...Bilal Amjad
 
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
 
Assembly language (coal)
Assembly language (coal)Assembly language (coal)
Assembly language (coal)Hareem Aslam
 
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 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
 
Representation of numbers and characters
Representation of numbers and charactersRepresentation of numbers and characters
Representation of numbers and characterswarda aziz
 
Assembly Language Lecture 1
Assembly Language Lecture 1Assembly Language Lecture 1
Assembly Language Lecture 1Motaz Saad
 
Unit 3 – assembly language programming
Unit 3 – assembly language programmingUnit 3 – assembly language programming
Unit 3 – assembly language programmingKartik Sharma
 

What's hot (20)

Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 5 (The Processor...
 
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
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
 
Assembly Langauge Chap 1
Assembly Langauge Chap 1Assembly Langauge Chap 1
Assembly Langauge Chap 1
 
Organization of the ibm personal computers
Organization of the ibm personal computersOrganization of the ibm personal computers
Organization of the ibm personal computers
 
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
 
Assignment on alp
Assignment on alpAssignment on alp
Assignment on alp
 
Solution manual of assembly language programming and organization of the ibm ...
Solution manual of assembly language programming and organization of the ibm ...Solution manual of assembly language programming and organization of the ibm ...
Solution manual of assembly language programming and organization of the ibm ...
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
 
Assembly 8086
Assembly 8086Assembly 8086
Assembly 8086
 
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
 
Assembly language (coal)
Assembly language (coal)Assembly language (coal)
Assembly language (coal)
 
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 ...
 
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 ...
 
Representation of numbers and characters
Representation of numbers and charactersRepresentation of numbers and characters
Representation of numbers and characters
 
Lesson 02
Lesson 02Lesson 02
Lesson 02
 
Assembly Language Lecture 1
Assembly Language Lecture 1Assembly Language Lecture 1
Assembly Language Lecture 1
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
 
Unit 3 – assembly language programming
Unit 3 – assembly language programmingUnit 3 – assembly language programming
Unit 3 – assembly language programming
 
Lesson 05
Lesson 05Lesson 05
Lesson 05
 

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

Multiplication & division instructions microprocessor 8086
Multiplication & division instructions microprocessor 8086Multiplication & division instructions microprocessor 8086
Multiplication & division instructions microprocessor 8086University of Gujrat, Pakistan
 
Taller practico emu8086_galarraga
Taller practico emu8086_galarragaTaller practico emu8086_galarraga
Taller practico emu8086_galarragaFabricio Galárraga
 
Assembly language programming
Assembly language programming Assembly language programming
Assembly language programming Gaurav Takrani
 
1344 Alp Of 8086
1344 Alp Of 80861344 Alp Of 8086
1344 Alp Of 8086techbed
 
Assembly language
Assembly languageAssembly language
Assembly languagebryle12
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086Vijay Kumar
 
Instructionsetof8086 180224060745(3)
Instructionsetof8086 180224060745(3)Instructionsetof8086 180224060745(3)
Instructionsetof8086 180224060745(3)AmitPaliwal20
 
6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumpingMomenMostafa
 
Instruction 4.pptx
Instruction 4.pptxInstruction 4.pptx
Instruction 4.pptxHebaEng
 
8086 instructions
8086 instructions8086 instructions
8086 instructionsRavi Anand
 
Microprocessor 8086-lab-mannual
Microprocessor 8086-lab-mannualMicroprocessor 8086-lab-mannual
Microprocessor 8086-lab-mannualyeshwant gadave
 
Home works summary.pptx
Home works summary.pptxHome works summary.pptx
Home works summary.pptxHebaEng
 
microp-8085 74 instructions for mct-A :P
microp-8085 74 instructions for mct-A :Pmicrop-8085 74 instructions for mct-A :P
microp-8085 74 instructions for mct-A :PJathin Kanumuri
 

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

Taller Ensambladores
Taller EnsambladoresTaller Ensambladores
Taller Ensambladores
 
Multiplication & division instructions microprocessor 8086
Multiplication & division instructions microprocessor 8086Multiplication & division instructions microprocessor 8086
Multiplication & division instructions microprocessor 8086
 
Al2ed chapter11
Al2ed chapter11Al2ed chapter11
Al2ed chapter11
 
[ASM]Lab7
[ASM]Lab7[ASM]Lab7
[ASM]Lab7
 
Taller practico emu8086_galarraga
Taller practico emu8086_galarragaTaller practico emu8086_galarraga
Taller practico emu8086_galarraga
 
Assembly language programming
Assembly language programming Assembly language programming
Assembly language programming
 
8086 instruction set
8086  instruction set8086  instruction set
8086 instruction set
 
1344 Alp Of 8086
1344 Alp Of 80861344 Alp Of 8086
1344 Alp Of 8086
 
Exp 03
Exp 03Exp 03
Exp 03
 
Assembly language
Assembly languageAssembly language
Assembly language
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 
Instructionsetof8086 180224060745(3)
Instructionsetof8086 180224060745(3)Instructionsetof8086 180224060745(3)
Instructionsetof8086 180224060745(3)
 
6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping
 
Module 2 (1).pptx
Module 2 (1).pptxModule 2 (1).pptx
Module 2 (1).pptx
 
Mod-2.pptx
Mod-2.pptxMod-2.pptx
Mod-2.pptx
 
Instruction 4.pptx
Instruction 4.pptxInstruction 4.pptx
Instruction 4.pptx
 
8086 instructions
8086 instructions8086 instructions
8086 instructions
 
Microprocessor 8086-lab-mannual
Microprocessor 8086-lab-mannualMicroprocessor 8086-lab-mannual
Microprocessor 8086-lab-mannual
 
Home works summary.pptx
Home works summary.pptxHome works summary.pptx
Home works summary.pptx
 
microp-8085 74 instructions for mct-A :P
microp-8085 74 instructions for mct-A :Pmicrop-8085 74 instructions for mct-A :P
microp-8085 74 instructions for mct-A :P
 

More from 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 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
 
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
 

More from 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 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 ...
 
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
 

Recently uploaded

Electromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptxElectromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptxNANDHAKUMARA10
 
Computer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesComputer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesChandrakantDivate1
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdfAldoGarca30
 
Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)Ramkumar k
 
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...jabtakhaidam7
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...drmkjayanthikannan
 
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesLinux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesRashidFaridChishti
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiessarkmank1
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdfKamal Acharya
 
fitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .pptfitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .pptAfnanAhmad53
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdfKamal Acharya
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdfKamal Acharya
 
Ground Improvement Technique: Earth Reinforcement
Ground Improvement Technique: Earth ReinforcementGround Improvement Technique: Earth Reinforcement
Ground Improvement Technique: Earth ReinforcementDr. Deepak Mudgal
 
Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...
Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...
Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...gragchanchal546
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network DevicesChandrakantDivate1
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxpritamlangde
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxMuhammadAsimMuhammad6
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 

Recently uploaded (20)

Electromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptxElectromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptx
 
Computer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesComputer Graphics Introduction To Curves
Computer Graphics Introduction To Curves
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)
 
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesLinux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
fitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .pptfitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .ppt
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Ground Improvement Technique: Earth Reinforcement
Ground Improvement Technique: Earth ReinforcementGround Improvement Technique: Earth Reinforcement
Ground Improvement Technique: Earth Reinforcement
 
Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...
Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...
Ghuma $ Russian Call Girls Ahmedabad ₹7.5k Pick Up & Drop With Cash Payment 8...
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 

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

  • 1.
  • 3.
  • 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