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

I was looking to get help with the last part of my lab (4) You are to modify the

ID: 3764248 • Letter: I

Question

I was looking to get help with the last part of my lab

(4) You are to modify the previous program in two steps so that it computes the (one-byte-long) sum of N unsigned one-byte data values (similar to Lab 3 Experiment (3)).

(Step 1) Data input from the PC keyboard: In the data section, use an assembler directive ds.b to reserve the following: • N: a one-byte space that specifies the number of bytes to be added up, followed by • Array, a 20-byte space for data to be summed up. Assume N is between one and twenty. These two variables will be initialized by inputs from the keyboard. Develop the following subroutine by first drawing the stack frame. • A subroutine labeled as “readInt” that reads from the SCI port a sequence of numerical characters and stores them as a one-byte-long integer. The string ends when the program encounters a “new line” character (i.e., the “Enter” key of the keyboard). The address of the integer should be passed using the CPU register X. For example, when a user types in “12 ”, the integer value becomes 0x0C. The program must call the subroutine to read N and Array values. It gets into an infinite loop at the end. Use the CodeWarrior debug window to verify the variable values. Demonstrate your program .

(Step 2) Compute the sum: In the data section, use an assembler directive ds.b to reserve an additional one-byte variable, sum. Modify the previous program to include the following subroutine. • A subroutine labeled as “addInt” that takes two input arguments, a one-byte long value about the number of bytes to be summed up and a two-byte-long starting address of the data area that contains those one-byte-long values. The subroutine returns the sum as a one-byte value. All input arguments and the return value should be passed through the stack frame. Assume there is no need to check for overflow. Draw the stack frame and demonstrate your program

This is what I am working from right now it works with just input from the keyboard and echoed back.

Explanation / Answer


.Ltext0:
                    .section   .rodata
                .LC0:
0000 20256420        .string   " %d , "
     202C2000
                .LC1:
0008 0A205375        .string   " Sum = %d "
     6D203D20
     25642000
                    .text
                    .globl   addInt
                addInt:
                .LFB0:
                    .cfi_startproc
0000 55              pushq   %rbp
                    .cfi_def_cfa_offset 16
                    .cfi_offset 6, -16
0001 4889E5         movq   %rsp, %rbp
                    .cfi_def_cfa_register 6
0004 4883EC20        subq   $32, %rsp
0008 897DEC         movl   %edi, -20(%rbp)
000b 488975E0        movq   %rsi, -32(%rbp)
000f C745F800        movl   $0, -8(%rbp)
     000000
0016 C745FC00        movl   $0, -4(%rbp)
     000000
001d EB44            jmp   .L2
                .L3:
005f 8345FC01        addl   $1, -4(%rbp)
001f 8B45FC         movl   -4(%rbp), %eax
0022 4898            cltq
0024 488D1485        leaq   0(,%rax,4), %rdx
     00000000
002c 488B45E0        movq   -32(%rbp), %rax
0030 4801D0         addq   %rdx, %rax
0033 8B00            movl   (%rax), %eax
0035 0145F8         addl   %eax, -8(%rbp)
0038 8B45FC         movl   -4(%rbp), %eax
003b 4898            cltq
003d 488D1485        leaq   0(,%rax,4), %rdx
     00000000
0045 488B45E0        movq   -32(%rbp), %rax
0049 4801D0         addq   %rdx, %rax
004c 8B00            movl   (%rax), %eax
004e 89C6            movl   %eax, %esi
0050 BF000000        movl   $.LC0, %edi
     00
0055 B8000000        movl   $0, %eax
     00
005a E8000000        call   printf
     00
                .L2:
0063 8B45FC         movl   -4(%rbp), %eax
0066 3B45EC         cmpl   -20(%rbp), %eax
0069 7CB4            jl   .L3
006b 8B45F8         movl   -8(%rbp), %eax
006e 89C6            movl   %eax, %esi
0070 BF000000        movl   $.LC1, %edi
     00
0075 B8000000        movl   $0, %eax
     00
007a E8000000        call   printf
     00
007f C9              leave
                    .cfi_def_cfa 7, 8
0080 C3              ret
                    .cfi_endproc
                .LFE0:
                    .globl   main
                main:
                .LFB1:
                    .cfi_startproc
0081 55              pushq   %rbp
                    .cfi_def_cfa_offset 16
                    .cfi_offset 6, -16
0082 4889E5         movq   %rsp, %rbp
                    .cfi_def_cfa_register 6
0085 4883EC60        subq   $96, %rsp
0089 C745AC00        movl   $0, -84(%rbp)
     000000
0090 EB13            jmp   .L5
                .L6:
00a1 8345AC01        addl   $1, -84(%rbp)
0092 8B45AC         movl   -84(%rbp), %eax
0095 8D5005         leal   5(%rax), %edx
0098 8B45AC         movl   -84(%rbp), %eax
009b 4898            cltq
009d 895485B0        movl   %edx, -80(%rbp,%rax,4)
                .L5:
00a5 837DAC13        cmpl   $19, -84(%rbp)
00a9 7EE7            jle   .L6
00ab 488D45B0        leaq   -80(%rbp), %rax
00af 4889C6         movq   %rax, %rsi
00b2 BF140000        movl   $20, %edi
     00
00b7 E8000000        call   addInt
     00
00bc B8000000        movl   $0, %eax
     00
00c1 C9              leave
                    .cfi_def_cfa 7, 8
00c2 C3              ret
                    .cfi_endproc
                .LFE1:
                .Letext0:

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