SlideShare una empresa de Scribd logo
1 de 9
Descargar para leer sin conexión
can you rewrite this code so that the teacher won't guess it is a copy ?
.MODEL SMALL
.STACK 100h
.DATA
N DW 0 ; number of integers to read
SIZE DB 0 ; size of each integer in bytes
SUM DD 0 ; sum of integers
AVG DD 0 ; average of integers
INPUT DB 20 ; input buffer for reading numbers as strings
.CODE
MAIN PROC
; Prompt the user to input N and the size of the integers
MOV AH, 9
LEA DX, PROMPT_N
INT 21h
CALL READ_DEC
MOV N, AX
MOV AH, 9
LEA DX, PROMPT_SIZE
INT 21h
CALL READ_DEC
MOV SIZE, AL
; Allocate memory for the integer array
MOV AH, 48h
MOV BX, N
MUL SIZE
MOV AH, 48h
INT 21h
MOV DI, AX
MOV BX, DI
; Loop to read N integers
MOV CX, N
MOV SI, 0
READ_LOOP:
; Prompt the user to input the next integer
MOV AH, 9
LEA DX, PROMPT_INT
INT 21h
; Read the input as a string
MOV AH, 0Ah
LEA DX, INPUT
INT 21h
; Convert the string to an integer in BCD format with SIZE bytes
CALL STR_TO_INT
MOV WORD PTR [DI], AX
ADD DI, SIZE
LOOP READ_LOOP
; Calculate the sum and average of the integers
MOV AX, 0
MOV DX, 0
MOV CX, N
MOV SI, BX
ADD_LOOP:
ADD SI, SIZE
MOV BX, WORD PTR [SI]
ADD AX, BX
ADC DX, 0
LOOP ADD_LOOP
MOV SUM, DX
MOV AVG, DX
SHR DX, 1
DIV CX
; Print the sum and average of the integers
MOV AH, 9
LEA DX, RESULT_SUM
INT 21h
CALL WRITE_DEC
MOV AH, 9
LEA DX, RESULT_AVG
INT 21h
CALL WRITE_DEC
; Exit the program
MOV AH, 4Ch
INT 21h
MAIN ENDP
; Read a decimal number from the keyboard and return it in AX
READ_DEC PROC
XOR AX, AX
MOV CX, 10
READ_DEC_LOOP:
; Read a character from the keyboard
MOV AH, 1
INT 21h
; Check if it's a decimal digit
CMP AL, '0'
JB READ_DEC_DONE
CMP AL, '9'
JA READ_DEC_DONE
; Multiply AX by 10 and add the new digit
SUB AL, '0'
MUL CX
ADD AX, AX
ADD AX, AX
ADD AX, AL
JMP READ_DEC_LOOP
READ_DEC_DONE:
RET
READ_DEC ENDP
; Convert the string in INPUT to an integer in BCD format with SIZE bytes and return it in AX
STR_TO_INT PROC
XOR AX, AX
XOR CX, CX
MOV SI, OFFSET INPUT+2
MOV DI, SI
ADD SI, SIZE-1
STR
; Check if the string is a decimal number
MOV CL, SIZE
DEC CL
CMP BYTE PTR [DI], '-'
JNE STR_SKIP_SIGN
NEG CL
DEC SI
STR_SKIP_SIGN:
MOV CH, 10
STR_CHECK_DIGIT_LOOP:
MOV AL, BYTE PTR [SI]
CMP AL, '0'
JB STR_NOT_DECIMAL
CMP AL, '9'
JA STR_NOT_DECIMAL
DEC SI
LOOP STR_CHECK_DIGIT_LOOP
; Convert the string to an integer in BCD format with SIZE bytes
MOV SI, OFFSET INPUT+2
MOV DI, AX
ADD DI, SIZE-1
STR_CONVERT_LOOP:
MOV AL, BYTE PTR [SI]
SUB AL, '0'
MOV BL, AL
MOV AL, CH
MUL BL
ADD AX, CX
MOV BL, AH
MOV AH, 0
MOV CL, 4
SHR BL, CL
ADD DI, 1
MOV BYTE PTR [DI], BL
MOV AL, AH
MOV BL, CH
MUL BL
ADD AX, CX
MOV BL, AL
MOV AH, 0
MOV CL, 4
SHR BL, CL
ADD DI, 1
MOV BYTE PTR [DI], BL
ADD SI, 1
CMP SI, OFFSET INPUT+2+20
JBE STR_CONVERT_LOOP
RET
STR_TO_INT ENDP
; Write a decimal number in AX to the console
WRITE_DEC PROC
; Convert the number to a string
XOR CX, CX
MOV BX, 10
WRITE_DEC_LOOP:
XOR DX, DX
DIV BX
PUSH DX
INC CX
OR AX, AX
JNZ WRITE_DEC_LOOP
; Write the string to the console
WRITE_DEC_LOOP2:
POP DX
ADD DL, '0'
MOV AH, 2
INT 21h
LOOP WRITE_DEC_LOOP2
RET
WRITE_DEC ENDP
; Data and messages
PROMPT_N DB 'Enter the number of integers to read: $'
PROMPT_SIZE DB 'Enter the size of each integer in bytes: $'
PROMPT_INT DB 'Enter the next integer: $'
RESULT_SUM DB 0Dh, 0Ah, 'The sum is: $'
RESULT_AVG DB 0Dh, 0Ah, 'The average is: $'
END MAIN
this is what the code should do
Write an Intel 8086 Assembly program that reads N numbers as Strings, convert them into
variable sized Integer numbers, and then print the summation and average of the numbers. The
program should allow the user to decide the size of the input number itself (assume integers in
format but with variable size). Detailed Description: - Have the program prompt the user to input
N and the size of the number then request inputting the first number, then the second and so on
until N numbers are input. - Your code should allow users to select the size of the numbers, for
example you can have integers with size of 1 Byte each, or you can make them 10 Bytes large. -
Validation: Your code should make sure user inputs Decimal numbers only, and with
predetermined size only. When a user inputs a wrong value, your code should print an error
message that explains it, and then gives the user another chance to input it correctly. - When the
user presses Enter, your code should read the input values as if they are Strings, then convert
them into numbers in BCD format with predefined size, each two digits can be stored in one
Byte. - After reading all the numbers, calculate their summation and average then print the Sum
and Avg

Más contenido relacionado

Similar a can you rewrite this code so that the teacher won't guess it is a copy (1).pdf

Assembly language programming
Assembly language programming Assembly language programming
Assembly language programming Gaurav Takrani
 
CUSP1. CUSP installedExecution of revised A12300.cspCo.docx
CUSP1. CUSP installedExecution of revised A12300.cspCo.docxCUSP1. CUSP installedExecution of revised A12300.cspCo.docx
CUSP1. CUSP installedExecution of revised A12300.cspCo.docxfaithxdunce63732
 
Part III: Assembly Language
Part III: Assembly LanguagePart III: Assembly Language
Part III: Assembly LanguageAhmed M. Abed
 
Stack and subroutine
Stack and subroutineStack and subroutine
Stack and subroutineAshim Saha
 
Introduction to ibm pc assembly language
Introduction to ibm pc assembly languageIntroduction to ibm pc assembly language
Introduction to ibm pc assembly languagewarda aziz
 
Instalación de emu8086
Instalación de emu8086Instalación de emu8086
Instalación de emu8086Alex Toapanta
 
Chapter 6 Flow control Instructions
Chapter 6 Flow control InstructionsChapter 6 Flow control Instructions
Chapter 6 Flow control Instructionswarda aziz
 
Assembly Language Compiler Implementation
Assembly Language Compiler ImplementationAssembly Language Compiler Implementation
Assembly Language Compiler ImplementationRAVI TEJA KOMMA
 
N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)Selomon birhane
 
Home works summary.pptx
Home works summary.pptxHome works summary.pptx
Home works summary.pptxHebaEng
 
Microprocessor 8086-lab-mannual
Microprocessor 8086-lab-mannualMicroprocessor 8086-lab-mannual
Microprocessor 8086-lab-mannualyeshwant gadave
 
1344 Alp Of 8086
1344 Alp Of 80861344 Alp Of 8086
1344 Alp Of 8086techbed
 
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
 

Similar a can you rewrite this code so that the teacher won't guess it is a copy (1).pdf (20)

Assembly language programming
Assembly language programming Assembly language programming
Assembly language programming
 
Practical notes
Practical notesPractical notes
Practical notes
 
CUSP1. CUSP installedExecution of revised A12300.cspCo.docx
CUSP1. CUSP installedExecution of revised A12300.cspCo.docxCUSP1. CUSP installedExecution of revised A12300.cspCo.docx
CUSP1. CUSP installedExecution of revised A12300.cspCo.docx
 
Part III: Assembly Language
Part III: Assembly LanguagePart III: Assembly Language
Part III: Assembly Language
 
Stack and subroutine
Stack and subroutineStack and subroutine
Stack and subroutine
 
Lab manual mp
Lab manual mpLab manual mp
Lab manual mp
 
Introduction to ibm pc assembly language
Introduction to ibm pc assembly languageIntroduction to ibm pc assembly language
Introduction to ibm pc assembly language
 
Mcs 17 solved assignment 2015- 16
Mcs 17 solved assignment 2015- 16Mcs 17 solved assignment 2015- 16
Mcs 17 solved assignment 2015- 16
 
Instalación de emu8086
Instalación de emu8086Instalación de emu8086
Instalación de emu8086
 
جميع اوامر لغة الاسمبلي
جميع اوامر لغة الاسمبلي جميع اوامر لغة الاسمبلي
جميع اوامر لغة الاسمبلي
 
Chapter 6 Flow control Instructions
Chapter 6 Flow control InstructionsChapter 6 Flow control Instructions
Chapter 6 Flow control Instructions
 
Assembly Language Compiler Implementation
Assembly Language Compiler ImplementationAssembly Language Compiler Implementation
Assembly Language Compiler Implementation
 
N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)
 
Home works summary.pptx
Home works summary.pptxHome works summary.pptx
Home works summary.pptx
 
8086 alp
8086 alp8086 alp
8086 alp
 
Microprocessor 8086-lab-mannual
Microprocessor 8086-lab-mannualMicroprocessor 8086-lab-mannual
Microprocessor 8086-lab-mannual
 
keyword
keywordkeyword
keyword
 
keyword
keywordkeyword
keyword
 
1344 Alp Of 8086
1344 Alp Of 80861344 Alp Of 8086
1344 Alp Of 8086
 
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 ...
 

Más de aksachdevahosymills

Carbonate minerals have a lower saturation state in more acidic (lower.pdf
Carbonate minerals have a lower saturation state in more acidic (lower.pdfCarbonate minerals have a lower saturation state in more acidic (lower.pdf
Carbonate minerals have a lower saturation state in more acidic (lower.pdfaksachdevahosymills
 
Carbon monoxide (CO) competitively inhibits the binding of oxygen to h.pdf
Carbon monoxide (CO) competitively inhibits the binding of oxygen to h.pdfCarbon monoxide (CO) competitively inhibits the binding of oxygen to h.pdf
Carbon monoxide (CO) competitively inhibits the binding of oxygen to h.pdfaksachdevahosymills
 
Carbon fixation is part of a metabolic process in plants (either photo.pdf
Carbon fixation is part of a metabolic process in plants (either photo.pdfCarbon fixation is part of a metabolic process in plants (either photo.pdf
Carbon fixation is part of a metabolic process in plants (either photo.pdfaksachdevahosymills
 
Capn Company began the current period with a $44-000 credit baiance in.pdf
Capn Company began the current period with a $44-000 credit baiance in.pdfCapn Company began the current period with a $44-000 credit baiance in.pdf
Capn Company began the current period with a $44-000 credit baiance in.pdfaksachdevahosymills
 
Canada values regional economic integration- Choose two of these agree.pdf
Canada values regional economic integration- Choose two of these agree.pdfCanada values regional economic integration- Choose two of these agree.pdf
Canada values regional economic integration- Choose two of these agree.pdfaksachdevahosymills
 
Canadian travelers can apply for NEXUS cards which allow them to use d.pdf
Canadian travelers can apply for NEXUS cards which allow them to use d.pdfCanadian travelers can apply for NEXUS cards which allow them to use d.pdf
Canadian travelers can apply for NEXUS cards which allow them to use d.pdfaksachdevahosymills
 
can you write about BNF as a tool and how we had to change an incorrec.pdf
can you write about BNF as a tool and how we had to change an incorrec.pdfcan you write about BNF as a tool and how we had to change an incorrec.pdf
can you write about BNF as a tool and how we had to change an incorrec.pdfaksachdevahosymills
 
Can you think of any other CEO that advertises their company's product.pdf
Can you think of any other CEO that advertises their company's product.pdfCan you think of any other CEO that advertises their company's product.pdf
Can you think of any other CEO that advertises their company's product.pdfaksachdevahosymills
 
Can you please read the case and help me about the question of- -Do yo.pdf
Can you please read the case and help me about the question of- -Do yo.pdfCan you please read the case and help me about the question of- -Do yo.pdf
Can you please read the case and help me about the question of- -Do yo.pdfaksachdevahosymills
 
can you please answer all Questions Question 1 ( 16 points- 2 points.pdf
can you please answer all Questions  Question 1 ( 16 points- 2 points.pdfcan you please answer all Questions  Question 1 ( 16 points- 2 points.pdf
can you please answer all Questions Question 1 ( 16 points- 2 points.pdfaksachdevahosymills
 
can you please answer the blank based on the info below thanks Pease.pdf
can you please answer the blank based on the info below  thanks  Pease.pdfcan you please answer the blank based on the info below  thanks  Pease.pdf
can you please answer the blank based on the info below thanks Pease.pdfaksachdevahosymills
 
Can you help me!- I'm trying to create a chatroom using Java Script an.pdf
Can you help me!- I'm trying to create a chatroom using Java Script an.pdfCan you help me!- I'm trying to create a chatroom using Java Script an.pdf
Can you help me!- I'm trying to create a chatroom using Java Script an.pdfaksachdevahosymills
 
Can you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdfCan you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdfaksachdevahosymills
 
Can you give me scientific papers that talk about Ways and methods of.pdf
Can you give me scientific papers that talk about Ways and methods of.pdfCan you give me scientific papers that talk about Ways and methods of.pdf
Can you give me scientific papers that talk about Ways and methods of.pdfaksachdevahosymills
 
Can you describe a time you acted with integrity- or someone you know.pdf
Can you describe a time you acted with integrity- or someone you know.pdfCan you describe a time you acted with integrity- or someone you know.pdf
Can you describe a time you acted with integrity- or someone you know.pdfaksachdevahosymills
 
Can you fix the errors- It isn't working when I try to run import s.pdf
Can you fix the errors- It isn't working when I try to run    import s.pdfCan you fix the errors- It isn't working when I try to run    import s.pdf
Can you fix the errors- It isn't working when I try to run import s.pdfaksachdevahosymills
 
Can you give me scientific papers that talk about a comparison between.pdf
Can you give me scientific papers that talk about a comparison between.pdfCan you give me scientific papers that talk about a comparison between.pdf
Can you give me scientific papers that talk about a comparison between.pdfaksachdevahosymills
 
Can someone help me with generating a frequency table please-(C++).pdf
Can someone help me with generating a frequency table please-(C++).pdfCan someone help me with generating a frequency table please-(C++).pdf
Can someone help me with generating a frequency table please-(C++).pdfaksachdevahosymills
 
can you analyze the five graphs and write comments about them Attach r.pdf
can you analyze the five graphs and write comments about them Attach r.pdfcan you analyze the five graphs and write comments about them Attach r.pdf
can you analyze the five graphs and write comments about them Attach r.pdfaksachdevahosymills
 
can you answer 1-3 pls 1- Study Power Point for Chapter 18- What gene.pdf
can you answer 1-3 pls  1- Study Power Point for Chapter 18- What gene.pdfcan you answer 1-3 pls  1- Study Power Point for Chapter 18- What gene.pdf
can you answer 1-3 pls 1- Study Power Point for Chapter 18- What gene.pdfaksachdevahosymills
 

Más de aksachdevahosymills (20)

Carbonate minerals have a lower saturation state in more acidic (lower.pdf
Carbonate minerals have a lower saturation state in more acidic (lower.pdfCarbonate minerals have a lower saturation state in more acidic (lower.pdf
Carbonate minerals have a lower saturation state in more acidic (lower.pdf
 
Carbon monoxide (CO) competitively inhibits the binding of oxygen to h.pdf
Carbon monoxide (CO) competitively inhibits the binding of oxygen to h.pdfCarbon monoxide (CO) competitively inhibits the binding of oxygen to h.pdf
Carbon monoxide (CO) competitively inhibits the binding of oxygen to h.pdf
 
Carbon fixation is part of a metabolic process in plants (either photo.pdf
Carbon fixation is part of a metabolic process in plants (either photo.pdfCarbon fixation is part of a metabolic process in plants (either photo.pdf
Carbon fixation is part of a metabolic process in plants (either photo.pdf
 
Capn Company began the current period with a $44-000 credit baiance in.pdf
Capn Company began the current period with a $44-000 credit baiance in.pdfCapn Company began the current period with a $44-000 credit baiance in.pdf
Capn Company began the current period with a $44-000 credit baiance in.pdf
 
Canada values regional economic integration- Choose two of these agree.pdf
Canada values regional economic integration- Choose two of these agree.pdfCanada values regional economic integration- Choose two of these agree.pdf
Canada values regional economic integration- Choose two of these agree.pdf
 
Canadian travelers can apply for NEXUS cards which allow them to use d.pdf
Canadian travelers can apply for NEXUS cards which allow them to use d.pdfCanadian travelers can apply for NEXUS cards which allow them to use d.pdf
Canadian travelers can apply for NEXUS cards which allow them to use d.pdf
 
can you write about BNF as a tool and how we had to change an incorrec.pdf
can you write about BNF as a tool and how we had to change an incorrec.pdfcan you write about BNF as a tool and how we had to change an incorrec.pdf
can you write about BNF as a tool and how we had to change an incorrec.pdf
 
Can you think of any other CEO that advertises their company's product.pdf
Can you think of any other CEO that advertises their company's product.pdfCan you think of any other CEO that advertises their company's product.pdf
Can you think of any other CEO that advertises their company's product.pdf
 
Can you please read the case and help me about the question of- -Do yo.pdf
Can you please read the case and help me about the question of- -Do yo.pdfCan you please read the case and help me about the question of- -Do yo.pdf
Can you please read the case and help me about the question of- -Do yo.pdf
 
can you please answer all Questions Question 1 ( 16 points- 2 points.pdf
can you please answer all Questions  Question 1 ( 16 points- 2 points.pdfcan you please answer all Questions  Question 1 ( 16 points- 2 points.pdf
can you please answer all Questions Question 1 ( 16 points- 2 points.pdf
 
can you please answer the blank based on the info below thanks Pease.pdf
can you please answer the blank based on the info below  thanks  Pease.pdfcan you please answer the blank based on the info below  thanks  Pease.pdf
can you please answer the blank based on the info below thanks Pease.pdf
 
Can you help me!- I'm trying to create a chatroom using Java Script an.pdf
Can you help me!- I'm trying to create a chatroom using Java Script an.pdfCan you help me!- I'm trying to create a chatroom using Java Script an.pdf
Can you help me!- I'm trying to create a chatroom using Java Script an.pdf
 
Can you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdfCan you finish and write the int main for the code according to the in.pdf
Can you finish and write the int main for the code according to the in.pdf
 
Can you give me scientific papers that talk about Ways and methods of.pdf
Can you give me scientific papers that talk about Ways and methods of.pdfCan you give me scientific papers that talk about Ways and methods of.pdf
Can you give me scientific papers that talk about Ways and methods of.pdf
 
Can you describe a time you acted with integrity- or someone you know.pdf
Can you describe a time you acted with integrity- or someone you know.pdfCan you describe a time you acted with integrity- or someone you know.pdf
Can you describe a time you acted with integrity- or someone you know.pdf
 
Can you fix the errors- It isn't working when I try to run import s.pdf
Can you fix the errors- It isn't working when I try to run    import s.pdfCan you fix the errors- It isn't working when I try to run    import s.pdf
Can you fix the errors- It isn't working when I try to run import s.pdf
 
Can you give me scientific papers that talk about a comparison between.pdf
Can you give me scientific papers that talk about a comparison between.pdfCan you give me scientific papers that talk about a comparison between.pdf
Can you give me scientific papers that talk about a comparison between.pdf
 
Can someone help me with generating a frequency table please-(C++).pdf
Can someone help me with generating a frequency table please-(C++).pdfCan someone help me with generating a frequency table please-(C++).pdf
Can someone help me with generating a frequency table please-(C++).pdf
 
can you analyze the five graphs and write comments about them Attach r.pdf
can you analyze the five graphs and write comments about them Attach r.pdfcan you analyze the five graphs and write comments about them Attach r.pdf
can you analyze the five graphs and write comments about them Attach r.pdf
 
can you answer 1-3 pls 1- Study Power Point for Chapter 18- What gene.pdf
can you answer 1-3 pls  1- Study Power Point for Chapter 18- What gene.pdfcan you answer 1-3 pls  1- Study Power Point for Chapter 18- What gene.pdf
can you answer 1-3 pls 1- Study Power Point for Chapter 18- What gene.pdf
 

Último

Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 

Último (20)

Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 

can you rewrite this code so that the teacher won't guess it is a copy (1).pdf

  • 1. can you rewrite this code so that the teacher won't guess it is a copy ? .MODEL SMALL .STACK 100h .DATA N DW 0 ; number of integers to read SIZE DB 0 ; size of each integer in bytes SUM DD 0 ; sum of integers AVG DD 0 ; average of integers INPUT DB 20 ; input buffer for reading numbers as strings .CODE MAIN PROC ; Prompt the user to input N and the size of the integers MOV AH, 9 LEA DX, PROMPT_N INT 21h CALL READ_DEC MOV N, AX MOV AH, 9 LEA DX, PROMPT_SIZE INT 21h CALL READ_DEC MOV SIZE, AL ; Allocate memory for the integer array
  • 2. MOV AH, 48h MOV BX, N MUL SIZE MOV AH, 48h INT 21h MOV DI, AX MOV BX, DI ; Loop to read N integers MOV CX, N MOV SI, 0 READ_LOOP: ; Prompt the user to input the next integer MOV AH, 9 LEA DX, PROMPT_INT INT 21h ; Read the input as a string MOV AH, 0Ah LEA DX, INPUT INT 21h ; Convert the string to an integer in BCD format with SIZE bytes CALL STR_TO_INT MOV WORD PTR [DI], AX ADD DI, SIZE
  • 3. LOOP READ_LOOP ; Calculate the sum and average of the integers MOV AX, 0 MOV DX, 0 MOV CX, N MOV SI, BX ADD_LOOP: ADD SI, SIZE MOV BX, WORD PTR [SI] ADD AX, BX ADC DX, 0 LOOP ADD_LOOP MOV SUM, DX MOV AVG, DX SHR DX, 1 DIV CX ; Print the sum and average of the integers MOV AH, 9 LEA DX, RESULT_SUM INT 21h CALL WRITE_DEC MOV AH, 9 LEA DX, RESULT_AVG
  • 4. INT 21h CALL WRITE_DEC ; Exit the program MOV AH, 4Ch INT 21h MAIN ENDP ; Read a decimal number from the keyboard and return it in AX READ_DEC PROC XOR AX, AX MOV CX, 10 READ_DEC_LOOP: ; Read a character from the keyboard MOV AH, 1 INT 21h ; Check if it's a decimal digit CMP AL, '0' JB READ_DEC_DONE CMP AL, '9' JA READ_DEC_DONE ; Multiply AX by 10 and add the new digit SUB AL, '0' MUL CX ADD AX, AX
  • 5. ADD AX, AX ADD AX, AL JMP READ_DEC_LOOP READ_DEC_DONE: RET READ_DEC ENDP ; Convert the string in INPUT to an integer in BCD format with SIZE bytes and return it in AX STR_TO_INT PROC XOR AX, AX XOR CX, CX MOV SI, OFFSET INPUT+2 MOV DI, SI ADD SI, SIZE-1 STR ; Check if the string is a decimal number MOV CL, SIZE DEC CL CMP BYTE PTR [DI], '-' JNE STR_SKIP_SIGN NEG CL DEC SI STR_SKIP_SIGN: MOV CH, 10
  • 6. STR_CHECK_DIGIT_LOOP: MOV AL, BYTE PTR [SI] CMP AL, '0' JB STR_NOT_DECIMAL CMP AL, '9' JA STR_NOT_DECIMAL DEC SI LOOP STR_CHECK_DIGIT_LOOP ; Convert the string to an integer in BCD format with SIZE bytes MOV SI, OFFSET INPUT+2 MOV DI, AX ADD DI, SIZE-1 STR_CONVERT_LOOP: MOV AL, BYTE PTR [SI] SUB AL, '0' MOV BL, AL MOV AL, CH MUL BL ADD AX, CX MOV BL, AH MOV AH, 0 MOV CL, 4 SHR BL, CL
  • 7. ADD DI, 1 MOV BYTE PTR [DI], BL MOV AL, AH MOV BL, CH MUL BL ADD AX, CX MOV BL, AL MOV AH, 0 MOV CL, 4 SHR BL, CL ADD DI, 1 MOV BYTE PTR [DI], BL ADD SI, 1 CMP SI, OFFSET INPUT+2+20 JBE STR_CONVERT_LOOP RET STR_TO_INT ENDP ; Write a decimal number in AX to the console WRITE_DEC PROC ; Convert the number to a string XOR CX, CX MOV BX, 10 WRITE_DEC_LOOP:
  • 8. XOR DX, DX DIV BX PUSH DX INC CX OR AX, AX JNZ WRITE_DEC_LOOP ; Write the string to the console WRITE_DEC_LOOP2: POP DX ADD DL, '0' MOV AH, 2 INT 21h LOOP WRITE_DEC_LOOP2 RET WRITE_DEC ENDP ; Data and messages PROMPT_N DB 'Enter the number of integers to read: $' PROMPT_SIZE DB 'Enter the size of each integer in bytes: $' PROMPT_INT DB 'Enter the next integer: $' RESULT_SUM DB 0Dh, 0Ah, 'The sum is: $' RESULT_AVG DB 0Dh, 0Ah, 'The average is: $' END MAIN this is what the code should do
  • 9. Write an Intel 8086 Assembly program that reads N numbers as Strings, convert them into variable sized Integer numbers, and then print the summation and average of the numbers. The program should allow the user to decide the size of the input number itself (assume integers in format but with variable size). Detailed Description: - Have the program prompt the user to input N and the size of the number then request inputting the first number, then the second and so on until N numbers are input. - Your code should allow users to select the size of the numbers, for example you can have integers with size of 1 Byte each, or you can make them 10 Bytes large. - Validation: Your code should make sure user inputs Decimal numbers only, and with predetermined size only. When a user inputs a wrong value, your code should print an error message that explains it, and then gives the user another chance to input it correctly. - When the user presses Enter, your code should read the input values as if they are Strings, then convert them into numbers in BCD format with predefined size, each two digits can be stored in one Byte. - After reading all the numbers, calculate their summation and average then print the Sum and Avg