Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Do with the minimum number of instructions. The “Main”routine calls subroutine c

ID: 3639642 • Letter: D

Question

Do with the minimum number of instructions.

The “Main”routine calls subroutine called “SumSeries”. SumSeries sums the integers from x to y inclusive, where x>0, y>0 and x<y. The input parameters x and y are passed to the subroutine in registers BL and CL, respectively. The output value of SumSeries, which is the sum computed, is passed via the register AL back to the calling procedure.

The Main procedure should output the value which is [the sum of integers from 1 to 5] plus [the sum of integers from 3 to 9].

pass the parameters x, y, and the output sum using the stack, assuming stack pointer is already been set appropriately and that ample space is available to store them on the stack.

Explanation / Answer

title Number Addition (add.asm) ; Dani Horowitz ; CSC111 x86 Assembly Programming ; This program adds integers a user inputs INCLUDE Irvine32.inc ;-------------------------------------------------- .stack ; begin stack segment ;-------------------------------------------------- .data ; begin data segment sum dword 0 counter dword 0 prompt byte "Enter a value: (0 to stop) ", 0 result byte "The sum of ", 0 count byte " numbers is ", 0 ;-------------------------------------------------- .code ; begin code segment ;-------------------------------------------------- ;-------------------------------------------------- prompt_user PROC ; ; Take a break! Pauses screen ;-------------------------------------------------- mov edx, OFFSET prompt ; prompt user to enter values call WriteString call Crlf GetValue: call ReadInt ; read integer from keyboard jo Overflow ; if ReadInt set overflow flag, jump to Overflow add sum, eax ; add entered value to accumulator sum jo Overflow ; if addition set overflow flag, jump to Overflow cmp eax, 0 ; did user enter 0? je Done ; if yes, goto Done inc counter ; increment counter jmp GetValue ; loop Overflow: mov eax, 0 mov sum, 0 Done: ret ;-------------------------------------------------- prompt_user ENDP ;-------------------------------------------------- ;-------------------------------------------------- print_sum PROC ; ; Take a break! Pauses screen ;-------------------------------------------------- mov edx, OFFSET result ; prints "The sum of " call WriteString mov eax, counter ; prints count of #s entered call WriteDec mov edx, OFFSET count ; prints " numbers is " call WriteString mov eax, sum ; prints sum call WriteDec call Crlf ret ;-------------------------------------------------- print_sum ENDP ;-------------------------------------------------- ;-------------------------------------------------- main proc ;-------------------------------------------------- call Clrscr ; clear screen call prompt_user ; get integers call print_sum ; print their sum exit main endp end main ;-------------------------------------------------- or ORG 100 / Origin of program is HEX 100 LDA ADS / Load first address of operand STA PTR / Store in pointer LDA NBR / Load -100 STA CTR / Store in counter CLA / Clear AC LOP, ADD PTR I / Add an operand to AC ISZ PTR / Increment pointer ISZ CTR / Increment counter BUN LOP / Repeat loop again STA SUM / Store sum HLT / Halt ADS, HEX 150 / First address of operands PTR, HEX 0 / Reserved for a pointer NBR, DEC -100 / Initial value for a counter CTR, HEX 0 / Reserved for a counter SUM, HEX 0 / Sum is stored here ORG 150 / Origin of operands is HEX 150 DEC 75 / First operand . . . DEC 23 END Anonymous

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote