Case Study Assembly language



There are three variable a = 4, b = 8, c = 12. Compare a and b, then
if A > B then D = A * B - C
If A = B, then compare B and C
            - If B > C, do D = A + B - C
            - if B = C, do D = A * B / C
            - If B < C, do D = A + B / C
If A < B Then D = A * C - B
all result are printed with description sentences.

Code for Macro.ASM


INCLUDE  PUSTAKA.MCR
.MODEL SMALL
.CODE
ORG 100h


Mulai :  JMP  Proses
                                 Kal0 DB 13,10,'PENYELESAIAN $'
                                 Kal1 DB 13,10,'A = $'
                                 Kal2 DB 13,10,'B = $'
                                 Kal3 DB 13,10,'C = $'                      
                                 Kal4 DB 13,10,'Karena A > B, maka A*B-C = $'
                                 Kal5 DB 13,10,'Karena A = B dan B > C, maka A+B-C = $'
                                 Kal6 DB 13,10,'Karena A = B dan B = C, maka A*B/C = $'
                                 Kal7 DB 13,10,'Karena A = B dan B < C, maka A+B/C = $'
                                 Kal8 DB 13,10,'Karena A < B, maka A*C-B = $'
                                 a Dw 4
                                 b Dw 8
                                 c Dw 12
                                 d Dw 0
                    
Proses:
                                                Cetak_Klm Kal0      
                                                Cetak_Klm Kal1
                                                Cetak_Angka a 
                                                Cetak_Klm Kal2
                                                Cetak_Angka b
                                                Cetak_Klm Kal3
                                                Cetak_Angka c

                                                MOV AX,a
                                                CMP AX,b
                                                ja aBesar
                                                je asama
                                                jb aKecil
                                               
aBesar                  :
                                                Cetak_Klm Kal4
                                                Perkalian a,b
                                                MOV d,AX
                                                Pengurangan d,c
                                                tampil
                                                JMP Keluar
aKecil                    :                                              
                                                Cetak_Klm Kal8
                                                Perkalian a,b
                                                MOV d,AX
                                                Pengurangan d,c
                                                tampil
                                                JMP Keluar        
asama                   :
                                                MOV AX,b
                                                CMP AX,c
                                                ja bBesar
                                                je bsama
                                                jb bKecil
                   bbesar  :           
                                                Cetak_Klm Kal5
                                                Perkalian a,b
                                                MOV d,AX
                                                Pengurangan d,c
                                                tampil
                                                JMP Keluar
                   bsama   :
                                                Cetak_Klm Kal6
                                                Perkalian a,b
                                                MOV d,AX
                                                Pembagian d,c
                                                tampil
                                                JMP Keluar
                   bkecil  :
                                                Cetak_Klm Kal7
                                                Pembagian b,c
                                                MOV d,AX
                                                Penjumlahan a,d
                                                tampil
                                                JMP Keluar
                               
Keluar  :
                                 INT   20h
END      Mulai

Code for Pustaka.MCR


Cetak_Kar           Macro Kar
                                                MOV AH,02
                                                MOV DL,Kar
                                                INT 21H
                                                EndM
                                               
Cetak_Klm  MACRO  Klm       
           LEA    DX,Klm    
           MOV    AH,09
           INT    21h
           ENDM
                                  
                     
Cetak_Angka MACRO Angka
                                                mov ax,angka
                                                Tampil
                                                endm
                               
Perkalian MACRO a,b
                                                MOV AX,a
                                                Mul b
                                                endm
                                               
Penjumlahan MACRO a,b
                                                MOV AX,a
                                                ADD AX,b
                                                endm
                                               
Pengurangan MACRO a,b
                                                MOV AX,a
                                                SUB AX,b
                                                endm
                                               
Pembagian MACRO a,b
                                                SUB  DX,DX
                                                MOV AX,a
                                                DIV b
                                                endm
                                               
Tampil Macro
                                                local looping, cetak
                                                mov bx,10
                                                xor cx,cx
                                                looping:
                                                xor dx,dx
                                                div bx
                                                push dx
                                                inc cx
                                                cmp ax,0
                                                jne looping
                                                cetak:
                                                pop dx
                                                add dl,'0'
                                                mov ah,02h
                                                int 21h
                                                loop cetak
                                                endM
Previous
Next Post »