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)

More Related Content

PPTX
Binary and hex input/output (in 8086 assembuly langyage)
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
PPT
Assembly Language Lecture 5
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
PDF
Chap 8 The stack and introduction to procedures & Chapter 9 multiplication an...
PPT
Loader
PDF
Unit 3 – assembly language programming
PPT
Assembly Language Basics
Binary and hex input/output (in 8086 assembuly langyage)
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Lecture 5
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Chap 8 The stack and introduction to procedures & Chapter 9 multiplication an...
Loader
Unit 3 – assembly language programming
Assembly Language Basics

What's hot (20)

PDF
assembly language programming and organization of IBM PC" by YTHA YU
PPTX
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
PDF
Basic Computer Organization and Design
PPTX
Shift Microoperations by Pir Sarfraz RSDT larkana
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
PPTX
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
PDF
Organization of the ibm personal computers
PDF
Assembly Langauge Chap 1
PDF
chapter 7 Logic, shift and rotate instructions
PPTX
Flow control instructions
PDF
8086 String Instructions.pdf
PPTX
1.5.1 Lect_parity.pptx
PPT
LEC 2-register transfer and register transfer language.ppt
PPTX
Register & Memory
PPTX
Conditional statement c++
PPTX
Single pass assembler
PDF
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
PPTX
Flag registers, addressing modes, instruction set
PPTX
Basic Computer Organization and Design
assembly language programming and organization of IBM PC" by YTHA YU
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
Basic Computer Organization and Design
Shift Microoperations by Pir Sarfraz RSDT larkana
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Organization of the ibm personal computers
Assembly Langauge Chap 1
chapter 7 Logic, shift and rotate instructions
Flow control instructions
8086 String Instructions.pdf
1.5.1 Lect_parity.pptx
LEC 2-register transfer and register transfer language.ppt
Register & Memory
Conditional statement c++
Single pass assembler
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Flag registers, addressing modes, instruction set
Basic Computer Organization and Design
Ad

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

PPTX
Multiplication & division instructions microprocessor 8086
PDF
Number System
PPTX
Basics of digital electronics
PDF
Binaty Arithmetic and Binary coding schemes
PDF
Taller Ensambladores
RTF
Microprocessor File
PPT
Counit2
PPTX
Unit 1 PDF.pptx
PDF
Digital Electronics – Unit I.pdf
PPTX
Computer Architecture and Organization- arithmetic
PPTX
Data Representation
PPTX
Basic pogramming concepts
PPTX
Data Representation
PPTX
6.number system
PPTX
Presentation of ICT.ppt.pptx
PPTX
Instruction 4.pptx
PPSX
Unit-6 Computer Arithmetic.ppsx
PPT
Module 4
PPTX
Data Representation
Multiplication & division instructions microprocessor 8086
Number System
Basics of digital electronics
Binaty Arithmetic and Binary coding schemes
Taller Ensambladores
Microprocessor File
Counit2
Unit 1 PDF.pptx
Digital Electronics – Unit I.pdf
Computer Architecture and Organization- arithmetic
Data Representation
Basic pogramming concepts
Data Representation
6.number system
Presentation of ICT.ppt.pptx
Instruction 4.pptx
Unit-6 Computer Arithmetic.ppsx
Module 4
Data Representation
Ad

More from Bilal Amjad (13)

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

Recently uploaded (20)

DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
DOCX
573137875-Attendance-Management-System-original
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
web development for engineering and engineering
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
CH1 Production IntroductoryConcepts.pptx
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
composite construction of structures.pdf
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPT
Project quality management in manufacturing
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
573137875-Attendance-Management-System-original
CYBER-CRIMES AND SECURITY A guide to understanding
web development for engineering and engineering
bas. eng. economics group 4 presentation 1.pptx
CH1 Production IntroductoryConcepts.pptx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Internet of Things (IOT) - A guide to understanding
composite construction of structures.pdf
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Foundation to blockchain - A guide to Blockchain Tech
R24 SURVEYING LAB MANUAL for civil enggi
Project quality management in manufacturing
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx

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