0

I have to write a program that will calculate the average of several numbers in/with Pep/8.

My main problem now is he didn't let us use DECI and we have to use CHARI but I can't make it go from number to number as the user can input up to 40 characters separated by spaces on that line before it gives off an error. I need to go from number to number and add them then divide by how many there are. Numbers are from -53 to 48. Also, we can't accept --40 or stuff like that.

How can I do that?

This is what I have until now for this part.

 STRO    msgb,d      
 STRO    msg,d
 LDX     0,i       
 CHARI   number,x    
 LDA     0,i 
 LDBYTEA number,x    
 STA total,d
 ADDX    1,i
 LDBYTEA number,x
 ADDA    number,x    
 STA total,d
 DECO   total,d     
 STOP   

 caract:  .BYTE   0           
 msgb:    .ASCII  "Welcome"
 .BYTE   0           
 msg:     .ASCII  "\nPlease enter numbers here: "
 .BYTE   0           
 nombre:  .WORD   0           
 total:   .WORD   0           
 .END                             
Maxime Lorant
  • 34,607
  • 19
  • 87
  • 97

1 Answers1

0

You should then write a subroutine that has the same function as DECI and invoke that in a loop. The subroutine itself should first check for an optional minus sign then read digits, multiplying the temporary result by ten in each step (you probably want to implement that using shift and add).

Also since PEP8 doesn't have division instruction, you'll have to write that for yourself too. I assume a trivial loop with subtraction should be fine for this excercise.

Jester
  • 56,577
  • 4
  • 81
  • 125