terça-feira, 3 de novembro de 2015

Programa média ponderada de notas
Ler as 2 notas do aluno: N1, N2
Calcular a média ponderada do aluno

                                     media = ( N1 + 4*N2) / 5 


Weighted average program from 0 ~ 20 notes 
Read 2 student grades: N1, N2
Calculate the weighted average student

                                     final score = (N1 + N2 * 4) / 5


Programme moyen pondéré de 0 ~ 20 notes
Lire 2 notes des étudiants: N1, N2
Calculer l'étudiant moyen pondéré

                                      score final = (N1 + N2 * 4) / 5



             org 1000h
N1:    ds 1
N2:    ds 1
       
             org 3000h
start:    lda N1  
             mov b,a ; the N1 we save at the b register
         
             lda N2   
             add a  ; here accumulator=2*N2
             add a  ; here we have accumulator 4*N2
           
             add b  ; in the accumulator we have N1+4*N2

             add a  ; lets two multiply all by 2 and then we must divide by 10
      
                      ; accumulator have now 2(N1+4*N2).
                      ; lets go to divide the accumulator by 10
  
             mvi c,0      ;  we use the register c to count the times that we
                               ; subtract the accumulator by 10 
             mvi d,10    ; we use d register to made the subtraction as sub d 
                           
 loop:    cpi 10     ; to see if accumulator is less then 10, if carry then a<10 
             jc theend
             sub d    ; its equal to do sui 10, note d is 10 but less expensive time
             inr c
             jmp loop
       

theend: rst 1 ; the media is at: the integer part at c regist
                     ; and decimal part at the acumulator 
             end  ;

Sem comentários:

Enviar um comentário