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

Program 3: Widgets Use to the Pep/9 environment, simple input/output and arithme

ID: 3800247 • Letter: P

Question

Program 3: Widgets

Use to the Pep/9 environment, simple input/output and arithmetic calculations.

A widget distributor receives a shipment of N widgets from the manufacturer. Unfortunately, oneeighth of them are not up to specification and cannot be shipped. The remaining widgets are shipped to a central warehouse.

A standard mailing box holds 16 widgets and costs $8 to mail. Any widgets left over are shipped

Individually at a cost of $2 each.

Write and test a Pep/9 assembly language program that inputs N and outputs the total cost of mailing the widgets. (Cost may be approximate because of limitations of integer arithmetic

Example

          N = 300 widgets are received from the manufacturer

          One eighth (37) are not up to specification leaving 263

          Sixteen boxes of 16 can be filled leaving 7 widgets to be shipped individually

          Total cost = (16 * $8) + (7 * $2) = $142

Program has to Loop, processing N until zero is entered – see example

Example program run

N: -2

N: 300

Cost to ship is $142

N: 20

Cost to ship is $12

N: 1

Cost to ship is $2

N: 32766

Cost to ship is $14358

N: 800

Cost to ship is $368

N: 200

Cost to ship is $110

N: 0

Goodbye

Explanation / Answer

CODE:


  
   pushq   %rbp
  
   movq   %rsp, %rbp
  
   subq   $32, %rsp
   movq   %fs:40, %rax
   movq   %rax, -8(%rbp)
   xorl   %eax, %eax
.L2:
   movl   $.LC0, %edi
   movl   $0, %eax
   call   printf
   leaq   -32(%rbp), %rax
   movq   %rax, %rsi
   movl   $.LC1, %edi
   movl   $0, %eax
   call   __isoc99_scanf
   movl   -32(%rbp), %eax
   leal   7(%rax), %edx
   testl   %eax, %eax
   cmovs   %edx, %eax
   sarl   $3, %eax
   movl   %eax, -28(%rbp)
   movl   -32(%rbp), %eax
   subl   -28(%rbp), %eax
   movl   %eax, -24(%rbp)
   movl   -24(%rbp), %eax
   leal   15(%rax), %edx
   testl   %eax, %eax
   cmovs   %edx, %eax
   sarl   $4, %eax
   sall   $3, %eax
   movl   %eax, -20(%rbp)
   movl   -24(%rbp), %eax
   cltd
   shrl   $28, %edx
   addl   %edx, %eax
   andl   $15, %eax
   subl   %edx, %eax
   addl   %eax, %eax
   movl   %eax, -16(%rbp)
   movl   -20(%rbp), %edx
   movl   -16(%rbp), %eax
   addl   %edx, %eax
   movl   %eax, -12(%rbp)
   movl   -12(%rbp), %eax
   movl   %eax, %esi
   movl   $.LC2, %edi
   movl   $0, %eax
   call   printf
   movl   -32(%rbp), %eax
   testl   %eax, %eax
   jle   .L2
   movl   $0, %eax
   movq   -8(%rbp), %rcx
   xorq   %fs:40, %rcx
   je   .L4

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