Assembly Program Example (APEx)


APEx:   SOLD       




Substance

Control Indicator

Control Indicator

Equipping the controller with an indicator in the form of an LED and its label. This indicator becomes more meaningful if we assume the seven segment display as an interface port that is already connected to another device, for example a queue portal, or others. #Microcontroller #8051


Example of Assembly Control Program Indicator Display

Source Code:

$MOD51 ; This includes 8051 definitions for the Metalink assembler

; Please insert your code here.
;- BAB3_13.ASM -------------------------------------------------------------------
;
; Penekanan tombol pd P2 dan hasil penekanan
; ditampilkan pada port 1 dan dikodekan ke penampil 7-seg di port 0
; author: www.bundet.com
;---------------------------------------------------------------------------------
 ORG     0H
MULAI:
 MOV  A,P2             ; Baca isi status tombol pada port 2 ke akumulator
 CJNE A,#0FEH,BANDING1 ; Apakah P2.0 ditekan?
                       ; tidak! cek lagi ke BANDING1
 MOV  P1,A             ; Ya! tampilkan hasil penekanan tombol di P2 ke P1
 MOV  P0,#0F9H         ; keluarkan kode angka 1 ke port 0
 SJMP MULAI            ; ulangi lagi dari awal

BANDING1:
 CJNE A,#0FDH,BANDING2 ; Apakah P2.1 ditekan?
                       ; tidak! cek lagi ke BANDING2
 MOV  P1,A             ; Ya! tampilkan hasil penekanan tombol di P2 ke P1
 MOV  P0,#0A4H         ; keluarkan kode angka 2 ke port 0
 SJMP MULAI

BANDING2:
 CJNE A,#0FBH,BANDING3 ; Apakah P2.2 ditekan?
                       ; tidak! cek lagi ke BANDING3
 MOV  P1,A             ; Ya! tampilkan hasil penekanan tombol di P2 ke P1
 MOV  P0,#0B0H         ; keluarkan kode angka 3 ke port 0
 SJMP MULAI

BANDING3:
 CJNE A,#0F7H,BANDING4 ; Apakah P2.3 ditekan?
                       ; tidak! cek lagi ke BANDING4
 MOV  P1,A             ; Ya! tampilkan hasil penekanan tombol di P2 ke P1
 MOV  P0,#99H          ; keluarkan kode angka 4 ke port 0
 SJMP MULAI

BANDING4:
 CJNE A,#0EFH,BANDING5 ; Apakah P2.4 ditekan?
                       ; tidak! cek lagi ke BANDING5
 MOV  P1,A             ; Ya! tampilkan hasil penekanan tombol di P2 ke P1
 MOV  P0,#92H          ; keluarkan kode angka 5 ke port 0
 SJMP MULAI

BANDING5:
 CJNE A,#0DFH,BANDING6 ; Apakah P2.5 ditekan?
                       ; tidak! cek lagi ke BANDING6
 MOV  P1,A             ; Ya! tampilkan hasil penekanan tombol di P2 ke P1
 MOV  P0,#82H          ; keluarkan kode angka 6 ke port 0
 SJMP MULAI

BANDING6:
 CJNE A,#0BFH,BANDING7 ; Apakah P2.6 ditekan?
                       ; tidak! cek lagi ke BANDING7
 MOV  P1,A             ; Ya! tampilkan hasil penekanan tombol di P2 ke P1
 MOV  P0,#0F8H         ; keluarkan kode angka 7 ke port 0
 SJMP MULAI

BANDING7:
 CJNE A,#07FH,MULAI    ; Apakah P2.7 ditekan?
                       ; tidak! ulangi lagi dari awal...
 MOV  P1,A             ; Ya! tampilkan hasil penekanan tombol di P2 ke P1
 MOV  P0,#80H          ; keluarkan kode angka 8 ke port 0
 SJMP MULAI

END

Demo:

https://youtu.be/R2mou6WQe6g

DOWNLOAD SCHEMATIC (180KB)

Port 2 Toggle Switch LED Running

By making port 2 a toggle switch whose function is to stop (pause) the LED running on port 0. #Microcontroller #8051


Example Program Assembly Port 2 Toggle Switch LED Running

Source Code:

$MOD51 ; This includes 8051 definitions for the Metalink assembler

; Please insert your code here.
;- BAB3_11.ASM -------------------------------------------------------------------
;
; penekanan tombol pd P2.0 sebagai toggle switch
; untuk menghentikan atau meneruskan lampu berjalan.
; author: www.bundet.com
; #Debugging
;---------------------------------------------------------------------------------
 ORG 0H

MULAI:
   MOV R5,#11111110B      ; Simpan data awal tampilan LED (P0.0 hidup dulu)
   MOV R4,#1              ; R4 sebagai status LED sedang berjalan atau tidak
                          ; awal diisi dengan R4=1 (artinya LED sedang berjalan)
CEK_TOMBOL:
   JNB P2.0,PROSES        ; Cek tombol P2.0 apakah ditekan atau tidak
                          ; Ya, P2.0 ditekan, lompat ke PROSES
   CALL LED_JALAN         ; Tidak, P2.0 tidak ditekan, teruskan proses
                          ; menjalankan LED berdasar status R4
   SJMP CEK_TOMBOL        ; ulangi lagi dari awal

PROSES:
   CJNE R4,#1,HIDUPKAN    ; Apakah sekarang LED sedang berjalan?
                          ; Tidak! lompatlah ke HIDUPKAN
   MOV R4,#0              ; Ya! Ubah status R4=0 (matikan LED berjalan)
   SJMP MULAI             ; ulangi lagi dari awal

HIDUPKAN:
   MOV R4,#1              ; Ubah status R4=1 (hidupkan LED berjalan)
   SJMP MULAI             ; ulangi lagi dari awal

LED_JALAN:
   CJNE R4,#1,MATI        ; Jika R4=1 maka teruskan menjalankan LED
                          ; Jika tidak, lompat ke MATI
   MOV P0,R5              ; isi register R5 dikirimkan ke port 1
   CALL DELAY             ; lakukan penundaan sesaat
   MOV A,R5               ; lakukan proses pemutaran bit ke kiri pada R5
   RL A                   ; melalui akumulator
   MOV R5,A
   RET
MATI:
   MOV P0,R5              ; isi register R5 selalu dikirimkan ke port 1
   CALL DELAY             ; lakukan penundaan sesaat
   RET

;-subrutin DELAY------------------------------------------------------------------
;
; subrutin ini hanya sekedar melakukan penundaan sesaat dengan cara
; mengulangi proses (pengurangan isi register) hingga dicapai suatu
; kondisi tertentu
;
;---------------------------------------------------------------------------------
Delay: Mov R0,#2        ; Isi Register R0 dengan 0 (2x ulang)
Delay1: Mov R1,#2       ; Isi Register R1 dengan 0 (2x ulang)
 Djnz R1,$
 Djnz R0,Delay1
 Ret
 End

Demo:

https://youtu.be/gHkwPgexuJ0

DOWNLOAD SCHEMATIC (123KB)

Port 2 Control 7 Segment

Displays Digital Numbers 1 - 7 by pressing each switch on port 2. #Microcontroller #8051


Example of Port 2 Control 7 Segment Assembly Program

Source Code:

$MOD51 ; This includes 8051 definitions for the Metalink assembler

; Please insert your code here.

;- BAB3_12.ASM -------------------------------------------------------------------
;
; Penekanan tombol pd P2 dan hasil penekanan
; ditampilkan pada display 7 segment di Port 0
; author: www.bundet.com
;---------------------------------------------------------------------------------
 ORG  0H
MULAI:
 MOV  A,P2             ; Baca isi status tombol pada port 2 ke akumulator
 CJNE A,#0FEH,BANDING1 ; Apakah P2.0 ditekan?
                       ; tidak! cek lagi ke BANDING1
 MOV  P0,#0F9H         ; ya ! keluarkan kode angka 1 7-seg ke Port 0
 SJMP MULAI            ; ulangi lagi dari awal

BANDING1:
 CJNE A,#0FDH,BANDING2 ; Apakah P2.1 ditekan?
                       ; tidak ! cek lagi ke BANDING2
 MOV  P0,#0A4H         ; ya ! keluarkan kode angka 2 7-seg ke port 0
 SJMP MULAI            ; ulangi lagi dari awal

BANDING2:
 CJNE A,#0FBH,BANDING3 ; Apakah P2.2 ditekan?
                       ; tidak ! cek lagi ke BANDING3
 MOV  P0,#0B0H         ; ya ! keluarkan kode angka 3 7-seg ke port 0
 SJMP MULAI            ; ulangi lagi dari awal

BANDING3:
 CJNE A,#0F7H,BANDING4 ; Apakah P2.3 ditekan?
                       ; tidak ! cek lagi ke BANDING4
 MOV  P0,#99H          ; ya ! keluarkan kode angka 4 7-seg ke port 0
 SJMP MULAI            ; ulangi lagi dari awal

BANDING4:
 CJNE A,#0EFH,BANDING5 ; Apakah P2.4 ditekan?
                       ; tidak ! cek lagi ke BANDING5
 MOV  P0,#92H          ; ya ! keluarkan kode angka 5 7-seg ke port 0
 SJMP MULAI            ; ulangi lagi dari awal

BANDING5:
 CJNE A,#0DFH,BANDING6 ; Apakah P2.5 ditekan?
                       ; tidak ! cek lagi ke BANDING6
 mov  P0,#82h          ; ya ! keluarkan kode angka 6 7-seg ke port 0
 sjmp mulai            ; ulangi lagi dari awal

BANDING6:
 CJNE A,#0BFH,BANDING7 ; Apakah P2.6 ditekan?
                       ; tidak ! cek lagi ke BANDING7
 MOV  P0,#0F8H         ; ya ! keluarkan kode angka 7 7-seg ke port 0
 SJMP MULAI            ; ulangi lagi dari awal

BANDING7:
 CJNE A,#07FH,MULAI    ; Apakah P2.7 ditekan?
                       ; tidak ! cek lagi ke BANDING8
 MOV  P0,#80H          ; ya ! keluarkan kode angka 8 7-seg ke port 0
 SJMP MULAI            ; ulangi lagi dari awal

END

Demo:

https://youtu.be/n6xEjmcQz40

DOWNLOAD SCHEMATIC (155KB)

Odd-Even Flip-Flop

By issuing logic 1 and 0 through two opposite directions. Often known as odd-even because each port with an odd collector is displayed alternately with an even collector, or vice versa, and so on (looping). #Microcontroller #8051


Odd-Even Flip-Flop Assembly Program Example

Source Code:

$MOD51 ; This includes 8051 definitions for the Metalink assembler

; Please insert your code here.
;---------------------------------------------------------------------------------
;
; Lampu flip-flop ganjil dan genap pada Port 0
; author: www.bundet.com
;---------------------------------------------------------------------------------
Org     0h

Mulai:
 Mov P0,#10101010B ; LED P0.1, P0.3, P0.5 dan P0.7 menyala (=0AAh)
 Acall Delay  ; lakukan penundaan sesaat...
 Mov P0,#01010101B ; LED P0.0, P0.2, P0.4 dan P0.6 menyala (=55h)
 Acall Delay  ; lakukan penundaan sesaat...
 Sjmp Mulai  ; ulangi lagi dari awal

;-subrutin DELAY-----------------------------------------------------------
;
; subrutin ini hanya sekedar melakukan penundaan sesaat dengan cara
; mengulangi proses (pengurangan isi register) hingga dicapai suatu
; kondisi tertentu
;
;--------------------------------------------------------------------------
DELAY:  MOV   R0,#1H            ; Isi Register R0 dengan 1 (1x ulang)
DELAY1: MOV   R1,#1H           ; Isi Register R1 dengan 1 (15x ulang
DELAY2: MOV   R2,#0             ; Isi register R2 dengan 0 (15x ulang)
        DJNZ  R2,$              ; R2=R2-1, jika R2 belum 0 ulangi lagi
        DJNZ  R1,DELAY2         ; R1=R1-1, jika R1 belum 0 ulangi DELAY2
        DJNZ  R0,DELAY1         ; R0=R0-1, jika R0 belum 0 ulangi DELAY1
        RET                     ; Kembali ke pemanggil subrutin DELAY

END

Demo:

https://youtu.be/3hfIRZOddj8

DOWNLOAD SCHEMATIC (117KB)

Port 2 As Switch Port 0

By making the condition of port 2 a toggle switch to turn off and/or on the LED on port 0. #Microcontroller #8051


Example of Assembly Program Port 2 As Port 0 Switch

Source Code:

$MOD51 ; This includes 8051 definitions for the Metalink assembler

; Please insert your code here.
;- BAB3_10.ASM -------------------------------------------------------------------
;
; Simulasi penekanan tombol pd P2.0 sebagai toggle switch
; untuk menghidupkan/mematikan lampu pada Port 0
; author: www.bundet.com
;---------------------------------------------------------------------------------
ORG  0H

MULAI:
 MOV  A,P2           ; Baca tombol P2 dan simpan di akumulator
 CJNE A,#0FEH,MULAI  ; Apakah tombol P2.0 ditekan? (=11111110)
                     ; Tidak! Ulangi lagi dari awal
 CJNE R0,#0,TERUS    ; Ya! Apakah R0=0 (artinya lampu sedang mati)?
                     ; Tidak! loncat ke proses mematikan lampu LED (TERUS)
 MOV  R0,#1          ; Ya! ubah status R0=1 (lampu menyala)
 MOV  P0,#0          ; dan hidupkan lampu LED di port 1

TUNGGU:              ; Untuk menghindari bouncing
 MOV  A,P2           ; Tunggu hingga tombol P2.0 dilepas
 CJNE A,#0FFH,TUNGGU ;
 SJMP MULAI          ; Ulangi lagi dari awal

TERUS:
 MOV  R0,#0          ; Ubah status R0=0 (lampu mati)
 MOV  P0,#0FFH       ; dan matikan lampu LED di port 1
 SJMP TUNGGU         ; untuk menghindari bouncing, lompat ke TUNGGU

 END

Demo:

https://youtu.be/xz-FOg0uZo4

DOWNLOAD SCHEMATIC (123KB)

LED Running Back and Forth

A variation of a dim LED animation running back and forth, with assembly programming downloaded to an 8051 microcontroller. Just for fun, I'm sure you can make it better and more interesting.


LED Assembly Program Example Running Back and Forth

Source Code:

$MOD51 ; This includes 8051 definitions for the Metalink assembler

; Please insert your code here.
;--------------------------------------------------------------------------------
;
; Lampu menyala pingpong kiri ke kanan, kanan ke kiri di port 0
; author: www.bundet.com
;---------------------------------------------------------------------------------
 Org   0h
 MOV   A, #0FEh       ; simpan data 11111110B ke akumulator (P0.0 menyala duluan)

MULAI:
 MOV   P0,A           ; kirim data ke Port 1
 ACALL DELAY          ; tunda sebentar
 RL    A              ; putar isi akumulator ke kiri 1 bit
 CJNE  A,#7FH,MULAI   ; apakah A=01111111B ? Tidak, ulangi lagi!

MULAI1:               ; Ya, lanjutkan ke proses berikut...
 MOV   P0,A           ; kirim data ke Port 1
 ACALL DELAY          ; tunda sebentar
 RR    A              ; putar isi akumulator ke kanan 1 bit
 CJNE  A,#0FEh,MULAI1 ; apakah A=11111110B ? Tidak, ulangi lagi!
 SJMP  MULAI          ; Ya, ulangi lagi dari paling awal...

;-subrutin DELAY------------------------------------------------------------------
;
; subrutin ini hanya sekedar melakukan penundaan sesaat dengan cara
; mengulangi proses (pengurangan isi register) hingga dicapai suatu
; kondisi tertentu
;
;---------------------------------------------------------------------------------
Delay:
Mov R0,#5            ; Isi Register R0 dengan 0 (5x ulang)

Delay1:
 Mov R1,#2h          ; Isi Register R1 dengan 0 (25x ulang)
 Djnz    R1,$
 Djnz R0,Delay1
 Ret

End

Demo:

https://youtu.be/8Obnzi6Bb_M

DOWNLOAD SCHEMATIC (117KB)

Netizens

Q1: ANDRI MARSEL Apr 28, 2017, 10:42:00 = Can you share the application, bro?

A1: It uses the multisim application, please download it at www.ni.com

Center Side Flip-Flop

LED animation runs from edge to center, and so on using 8051 microcontroller.


Example of Center-Edge Flip-Flop Assembly Program

Source Code:

$MOD51 ; This includes 8051 definitions for the Metalink assembler

; Please insert your code here.
;---------------------------------------------------------------------------------
;
; Lampu bergerak dari pinggir ke tengah kemudian kembali lagi...
; author: www.bundet.com
;---------------------------------------------------------------------------------
Org     0h

Mulai:
 Mov P0,#11100111B  ; Dua lampu tengah menyala, P0.3 dan P0.4 (=0E7h)
 Acall Delay        ; lakukan penundaan sesaat...
 Mov P0,#11011011B  ; Dua lampu berikutnya menyala, P0.2 dan P0.5 (=0DBh)
 Acall Delay        ; lakukan penundaan sesaat...
 Mov P0,#10111101B  ; Dua lampu berikutnya menyala, P0.1 dan P0.6 (=0BDh)
 Acall Delay
 Mov P0,#01111110B  ; Dua lampu berikutnya menyala, P0.0 dan P0.7 (=7Eh)
 Acall Delay
 Mov P0,#10111101B  ; dua lampu berikutnya menyala, P0.1 dan P0.6 (=0BDh)
 Acall Delay
 Mov P0,#11011011B  ; Dua lampu berikutnya menyala, P0.2 dan P0.5 (=0DBh)
 Acall Delay
 Sjmp Mulai         ; Lompat ke alamat dg label Mulai

;-subrutin DELAY-----------------------------------------------------------
;
; subrutin ini hanya sekedar melakukan penundaan sesaat dengan cara
; mengulangi proses (pengurangan isi register) hingga dicapai suatu
; kondisi tertentu
;
;--------------------------------------------------------------------------
DELAY:  MOV   R0,#1H            ; Isi Register R0 dengan 1 (1x ulang)
DELAY1: MOV   R1,#1H            ; Isi Register R1 dengan 1 (11x ulang
DELAY2: MOV   R2,#0             ; Isi register R2 dengan 0 (12x ulang)
        DJNZ  R2,$              ; R2=R2-1, jika R2 belum 0 ulangi lagi
        DJNZ  R1,DELAY2         ; R1=R1-1, jika R1 belum 0 ulangi DELAY2
        DJNZ  R0,DELAY1         ; R0=R0-1, jika R0 belum 0 ulangi DELAY1
        RET                     ; Kembali ke pemanggil subrutin DELAY
END

Demo:

https://youtu.be/hCfkA9Dp_C0

DOWNLOAD SCHEMATIC (117KB)

LED Light Running

An assembly programming to display an animation of an LED flashing using an 8051 microcontroller.


Example of LED Assembly Program Running

Source Code:

$MOD51 ; This includes 8051 definitions for the Metalink assembler

; Please insert your code here.
;--------------------------------------------------------------------------------
;
; Lampu berjalan dari P0.0 s/d P0.7 kemudian kembali lagi
; author: www.bundet.com
;---------------------------------------------------------------------------------
Org     0h

Mov A,#00000001B  ; data lampu menyala dikirim melalui akumulator
                  ; agar P0.0 pertama kali menyala, akumulator
                  ; diisi dengan 11111110B atau 0FEh
Mulai:
  Mov P0,A        ; kirimkan data di akumualtor ke port 1
  Acall Delay     ; lakukan penundaan sesaat
  RL A            ; rotasikan isi akumulator ke kiri
                  ; +->------>----->----->+
                  ; |                     |
                  ; +<--7-6-5-4-3-2-1-0<--+
 Sjmp Mulai       ; ulangi lagi dari awal

;-subrutin DELAY------------------------------------------------------------------
;
; subrutin ini hanya sekedar melakukan penundaan sesaat dengan cara
; mengulangi proses (pengurangan isi register) hingga dicapai suatu
; kondisi tertentu
;
;---------------------------------------------------------------------------------
Delay:
 Mov R0, #1h  ; Isi Register R0 dengan 0 (256x ulang)
Delay1:
 Mov R1, #0   ; Isi Register R1 dengan 0 (256x ulang)
 Djnz R1,$
 Djnz R0,Delay1
 Ret

End

Demo:

https://youtu.be/UcKWAikdGHs

DOWNLOAD SCHEMATIC (117KB)

Other Variations

Source code:

;=====================================
; bundet.com
; VARIASI LED BERJALAN
;=====================================
#include <sfr51.inc>
 ORG      00H
 mov A, #00000001b
MULAI:  RR A
 MOV P2, A
 MOV P0, A
 ACALL TUNDA
  SJMP MULAI

TUNDA:  MOV   R0, #001h
TUNDA1: MOV   R1, #0FFH
TUNDA2: MOV   R2, #0FFH
TUNDA3: NOP
   DJNZ  R2, TUNDA3
     DJNZ  R1, TUNDA2
   DJNZ  R0, TUNDA1
   RET
   END

Demo:

https://youtu.be/5Pco-M1RfwM

Hope this is useful & happy learning!

Flip Flop Port 0

A simple program made by a technician to entertain his younger siblings maybe, or even to entertain himself who has been lonely for too long. Well, the side effect of a programmer who has been busy with coding and machines for too long, makes him forget about the real world where there are still many women who need his affection  😃 "#aghiaag-uhuk".


Example of Port 0 Flip-Flop Assembly Program

Still using the flagship device, namely 8051, equipped with several LEDs on port 0 to display unique patterns from the following program:

$MOD51 ; This includes 8051 definitions for the Metalink assembler

; Please insert your code here.
;---------------------------------------------------------------
;
; Lampu flip-flop pada Port 0
; #author: www.bundet.com
;--------------------------------------------------------------------------
ORG   0H   ; program ditempatkan pada lokasi 0000H
;
MULAI:  MOV   P0,#00001111B     ; LED P0.4 s/d P1.7 nyala (heksa= #0FH)
        ACALL DELAY             ; lakukan penundaan sesaat (sub. DELAY)
        MOV   P0,#11110000B     ; LED P0.0 s/d P1.3 nyala (heksa= #0F0H)
        ACALL DELAY             ; lakukan penundaan sesaat (sub. DELAY)
        SJMP  MULAI             ; ulangi lagi dari awal

;-subrutin DELAY-----------------------------------------------------------
;
; subrutin ini hanya sekedar melakukan penundaan sesaat dengan cara
; mengulangi proses (pengurangan isi register) hingga dicapai suatu
; kondisi tertentu
;
;--------------------------------------------------------------------------
DELAY:  MOV   R0,#2H            ; Isi Register R0 dengan 2 (2x ulang)
DELAY1: MOV   R1,#2H            ; Isi Register R1 dengan 2 (2x ulang
DELAY2: MOV   R2,#0             ; Isi register R2 dengan 0 (2x ulang)
        DJNZ  R2,$              ; R2=R2-1, jika R2 belum 0 ulangi lagi
        DJNZ  R1,DELAY2         ; R1=R1-1, jika R1 belum 0 ulangi DELAY2
        DJNZ  R0,DELAY1         ; R0=R0-1, jika R0 belum 0 ulangi DELAY1
        RET                     ; Kembali ke pemanggil subrutin DELAY

END

Demo:

https://youtu.be/WJmqDDrd4vM

DOWNLOAD SCHEMATIC (117KB)

Multi Switch

Manipulate the port pressure on P0.0 as a switch to turn something on, and P0.1 as a switch to turn something off. Delay (Time Delay) and Value port can be set in such a way, so as to adjust to the configuration of external equipment that you want to connect or control. #Microcontroller #8051


Assembly Program Example As Multiple Switches

Source Code:

$MOD51 ; This includes 8051 definitions for the Metalink assembler

; Please insert your code here.
;- BAB3_09.ASM -------------------------------------------------------------------
;
; Manipulasi tombol pd P0.0 untuk menghidupkan
; dan P0.1 untuk mematikan LED pada Port 0
; #Mikrokontroller sebagai multisaklar
; #author: www.bundet.com
;
;---------------------------------------------------------------------------------

ORG  0H
;-----------------7$egmant----------------------
start:  mov P0,#00001000b
        call delay
        mov P0,#11101110b
        call delay
        mov P0,#10010100b
        call delay
        mov P0,#11000100b
        call delay
        mov P0,#11100010b
        call delay
        mov P0,#11000001b
        call delay
        mov P0,#10000001b
        call delay
        mov P0,#11101100b
        call delay
        mov P0,#10000000b
        call delay
        mov P0,#11000000b
        call delay
        mov P0,#10100000b
        call delay
        mov P0,#10000000b
        call delay
        mov P0,#10011001b
        call delay
        jmp start
delay:  mov r1,#09h
delay1: mov r2,#09h
delay2: mov r3,#09h
delay3: nop
        djnz r3,delay3
        djnz r2,delay2
        djnz r1,delay1
        ret

END

Demo:

https://youtu.be/momYSRJIIAo

DOWNLOAD SCHEMATIC (117KB)

Push-Button Switch Microcontroller Experiment

OBJECTIVE:

  1. Students understand microcontroller circuits with interfaces to switches.
  2. Students can understand assembly programs to take switch data and output data to LEDs.
  3. Students understand some basic assembly instructions, MOV, Setb, Clr, RL and RR.


Figure 2.2. Push Button Interface Circuit 

In Figure 2.2.a, a push button circuit is shown. If the switch is pressed, the port corresponding to that bit will receive a low logic '0' and vice versa. If the switch is not pressed, the port will receive a high logic '1'.

Experiment 2.1. Get Switch Data

In this experiment, the LED will light up when the switch is pressed according to the bit. To do this experiment, do the following steps:

  1. Open the jumper on EN_DAC if it is connected.
  2. Connect the Microcontroller Trainer module to the +5V power supply.
  3. Connect the Microcontroller Trainer module to the programmer circuit 
  4. Open the M-IDE Studio for MCS-51 program, as a program editor and compiler.
  5. Type the following program: ( download file prog21a.asm ) 
    Org 0h
    Start: Mov A, P2 ;Ambil data dari P2 dan Simpan ke A
               CPL A ;Komplemen/ Invert terhadap A
               Mov P0, A ;Kirim data A ke P0
               sjmp start
               end
  6. Save the program you typed and name it: prog21a.asm
  7. In the MIDE program, select Build /F9 or to compile the program from *.asm to *.hex.
  8. Program the microcontroller using the ISP Software Program (See Instructions for Use)
  9. Make observations on the LED.
| Saklar | Kondisi LED yang Nyala (D1-D2-D3-D4-D5-D6-D7-D8) |
|--------|--------------------------------------------------|
| SW1    |                                                  |
| SW2    |                                                  |
| SW3    |                                                  |
| SW4    |                                                  |
| SW5    |                                                  |
| SW6    |                                                  |
| SW7    |                                                  |
| SW8    |                                                  |

Experiment 2.2. Rotate Right-Left

In this experiment, the LED will run to the right or left following the pressing of the P2.0 or P2.1 button. To do this experiment, do the following steps:

  1. Connect the Microcontroller Trainer module to the +5V power supply.
  2. Connect the Microcontroller Trainer module to the programmer circuit 
  3. Open the M-IDE Studio for MCS-51 program, as a program editor and compiler.
  4. Type the following program: ( download file prog22a.asm ) 
    org 0h
    CekP20:  JB P2.0,CekP21 ; Menguji bit P2.0, apakah adalah logika '1'
                       call RLeft ; Jika P2.0=0, maka LED putar kiri
    CekP21: JB P2.1,CekP20 ; Menguji bit P2.1, apakah adalah logika '1'
                      call RRight ; Jika P2.1=0, maka LED putar kanan
                      sjmp CekP20 ; jump forever to CekP2.0
    ;========================================
    ;Subrutin ini digunakan untuk menggerakkan LED Ke Kanan
    ;========================================
    RLeft:    mov A,#11111110b;send data to Acc
    RLeft1: mov P0,A ;send data to P0
                   call delay ;call delay time
                   JB P2.1,RLeft2 ;Menguji bit P2.1, apakah adalah logika '1'
                   sjmp EndRLeft ;Jika P2.1=0, maka lompat ke EndRLeft
    RLeft2: RL A
    sjmp RLeft1
    EndRLeft: ret
    ;
    ;======================================
    ;Subrutin ini digunakan untuk menggerakkan LED Ke Kiri
     ;======================================
    RRight:   mov A,#01111111b;send data to Acc
    RRight1: mov P0,A ;send data to P0
                      call delay ;call delay time
                      JB P2.0,RRight2 ;Menguji bit P2.0, apakah adalah logika '1'
                      sjmp EndRRight ;Jika P2.0=0, maka lompat ke EndRRight
    RRight2: RR A
                      sjmp RRight1
    EndRRight: ret
    ;=======================================
    ;subroutine delay time
    ;=======================================
    delay: mov R1,#255
    del1: mov R2,#255
    del2: djnz R2,del2
               djnz R1,del1
               ret
               end
  5. Save the program you typed and name it: prog22a.asm
  6. In the MIDE program, select Build /F9 or to compile the program from *.asm to *.hex.
  7. Program the microcontroller using the ISP Software Program (See Instructions for Use)
  8. Make observations on the LED.
  9. Make modifications to the experiment accordingly by replacing the ports with P2.2 (rotate right) and P2.3 (rotate left).

Experiment 2.3. Setting Up/Dn and Enter with LED display

In this experiment, the ON LED will increase or decrease following the pressing of the P2.1 (UP) or P2.2 (DN) buttons. The LED will stop increasing or decreasing when the P2.0 (ENTER) button is pressed. To do this experiment, do the following steps:

  1. Connect the Microcontroller Trainer module to the +5V power supply.
  2. Connect the Microcontroller Trainer module to the programmer circuit 
  3. Open the M-IDE Studio for MCS-51 program, as a program editor and compiler ( download the file prog23a.asm )
  4. Type the following program:
    org 0h
    start:
          mov R7,#1 ;inisialisasi data setting
    Setup:mov A,R7 ;simpan data R7 ke A
          cpl A ;komplemen A,
          mov P0,A ;output data ke LED
          jnb p2.0,getout;bilasw1(P2.0)ditekan mkgetout(selesai)
          jb P2.1,SetDn ;bila sw2(P2.1) ditekan mk INC R7
          inc R7 ;R7:=R7+1
          acall delay ;waktu tunda, antar penekanan tombol
          cjne R7,#100d,setup;deteksi apakah setting=100d
          mov R7,#1 ;reset R7 -> 1
          sjmp Setup
               ;
    SetDn:Mov A,R7 ;simpan data R7 ke A
          cpl A ;komplemen A,
          mov P0,A ;output data ke LED
          jnb P2.0,getout;bila sw1(P2.0)ditekan mkgetoutselesai)
          jb p2.2,Setup ;bila sw2(P2.1) ditekan mk INC R7
          dec R7 ;R7:=R7-1
          acall delay ;waktu tunda lama penekanan tombol
          cjne R7,#0d,setDn;deteksi apakah setting=0d
          mov R7,#1d ;reset R7 -> 1
          sjmp Setdn
    getout:
          sjmp getout
               ;
    delay:mov R0,#255
    delay1:mov R2,#255
          djnz R2,$
          djnz R0,delay1
          ret
    
          end
    1. Save the program you typed and name it: prog23a.asm
    2. In the MIDE program, select Build /F9 or to compile the program from *.asm to *.hex.
    3. Program the microcontroller using the ISP Software Program (See Instructions for Use)
    4. Make observations on the LED.
    5. Make modifications to the experiment accordingly by replacing the ports with P2.5 (Setting UP), P2.6 (Setting Dn) and P2.7 (Enter).

Assembly Programming & LED Machine Walking (Ring Counter)

ASSIGNMENT! Create a program to light up a row of LEDs according to the following truth table:

| D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 | Data |
|----|----|----|----|----|----|----|----|------|
| 0  | 0  | 0  | 0  | 0  | 0  | 0  | 1  | 01   |
| 0  | 0  | 0  | 0  | 0  | 0  | 1  | 0  | 02   |
| 0  | 0  | 0  | 0  | 0  | 1  | 0  | 0  | 04   |
| 0  | 0  | 0  | 0  | 1  | 0  | 0  | 0  | 08   |
| 0  | 0  | 0  | 1  | 0  | 0  | 0  | 0  | 10   |
| 0  | 0  | 1  | 0  | 0  | 0  | 0  | 0  | 20   |
| 0  | 1  | 0  | 0  | 0  | 0  | 0  | 0  | 40   |
| 1  | 0  | 0  | 0  | 0  | 0  | 0  | 0  | 80   |

The program runs 10 times & the program runs continuously and stops after the reset button [RST]

Completion

Algorithm Structure

| Isi Accu dengan data 01                    |
|--------------------------------------------|
| Keluarkan isi Accu ke Register Control     |
| Isi Register B = 0A                        |
| B = 0                                      |
|            Isi Accu dengan data 01         |
|            keluarkan isi Accu ke port A    |
|            Tunda Waktu                     |
|            Isi Accu dengan data 02         |
|            Keluarkan isi Accu ke port A    |
|            Tunda Waktu                     |
|            Isi Accu dengan data 04         |
|            Keluarkan isi Accu ke port A    |
|            Tunda Waktu                     |
|            Isi Accu dengan data 08         |
|            Keluarkan isi Accu ke port A    |
|            Tunda Waktu                     |
|            Isi Accu dengan data 10         |
|            Keluarkan isi Accu ke port A    |
|            Tunda Waktu                     |
|            Isi Accu dengan data 20         |
|            Keluarkan isi Accu ke port A    |
|            Tunda Waktu                     |
|            Isi Accu dengan data 40         |
|            Keluarkan isi Accu ke port A    |
|            Tunda Waktu                     |
|            Isi Accu dengan data 80         |
|            Keluarkan isi Accu ke port A    |
|            Tunda Waktu                     |
|            Kurangi dengan 1 isi Register B |
| Isi Accu dengan data 00                    |
| Keluarkan isi Accu ke port A               |
| Akhiri program                             |

Subroutine

| Isi Pas Register HL = FF FF                         |
|-----------------------------------------------------|
| H = 0                                               |
|            L = 0                                    |
|                     Kurangi dengan 1 isi Register L |
|            Kurangi dengan 1 isi Register H          |
| RET UNC                                             |

Program Structure

| Alamat     | Assembly      | Mesin    |
|------------|---------------|----------|
| 1800       | LDA, 80       | 3E 80    |
| 1802       | OUT (43), A   | D3 43    |
| 1804       | LDB, 0A       | 06 0A    |
| 1805       | NOP           | 00       |
| 1807       | LDA, 01       | 3E 01    |
| 1809       | OUT (40), A   | D3 40    |
| 180B       | CALL UNC 1A00 | CD 00 1A |
| 180E       | LDA, 02       | 3E 02    |
| 1810       | OUT (40), A   | D3 40    |
| 1812       | CALL UNC 1A00 | CD 00 1A |
| 1815       | LDA, 04       | 3E 04    |
| 1817       | OUT (40), A   | D3 40    |
| 1819       | CALL UNC 1A00 | CD 00 1A |
| 181C       | LDA, 08       | 3E 08    |
| 181E       | OUT (40), A   | D3 40    |
| 1820       | CALL UNC 1A00 | CD 00 1A |
| 1823       | LDA, 10       | 3E 10    |
| 1825       | OUT (40), A   | D3 40    |
| 1827       | CALL UNC 1A00 | CD 00 1A |
| 182A       | LDA, 20       | 3E 20    |
| 182C       | OUT (40), A   | D3 40    |
| 182D       | CALL UNC 1A00 | CD 00 1A |
| 1831       | LDA, 40       | 3E 40    |
| 1833       | OUT (40), A   | D3 40    |
| 1835       | CALL UNC 1A00 | CD 00 1A |
| 1838       | LDA, 80       | 3E 80    |
| 183A       | OUT (40), A   | D3 40    |
| 183C       | CALL UNC 1A00 | CD 00 1A |
| 183F       | DEC B         | 05       |
| 1840       | JPNZ 1806     | C2 06 18 |
| 1843       | LDA, 00       | 3E 00    |
| 1845       | OUT (40), A   | D3 40    |
| 1847       | RST 0038      | FF       |
| SUBROUTINE |               |          |
| 1A00       | LDHL, FF FF   | 21 FF FF |
| 1A03       | NOP           | 00       |
| 1A04       | NOP           | 00       |
| 1A05       | DEC L         | 2D       |
| 1A06       | JPNZ 1A04     | C2 04 18 |
| 1A09       | DEC H         | 25       |
| 1A0A       | JPNZ 1A03     | C2 03 18 |
| 1A0D       | RET UNC       | C9       |

Hope this is useful & happy learning!

Comment 1

ANONYMOUS Jul 4, 2015, 23:54:00 Wow, great, bro.. I've saved several of your articles.. they're all interesting.. but because you have a lot of articles, I only saved a few.. hehe I like the ones about Linux OS, assembly, radio, computers, and anything IT related..

Response 1

Hello young scholars, thank you and welcome to the digital world.

Outputting Sequential Bit Data with 4 Shift Instruction Models

Substance:

  1. Outputting data sequentially with some variation of the shift instruction
  2. Conditioning the battery = 01 --> A = A+A in repetition
  3. Using 4 variations of the swipe instruction, such as:

1. SLA (Shift Left Arithmetic) 

2. SRA (Shift Right Arithmetic)

3. SRL (Shift Right Logic)

4. RLC (Rotation Left Circular)

METHOD 1

Algorithm Structure

| Isi Accu dengan data kendali port A = B = C = OUT 80h |
|-------------------------------------------------------|
| Keluarkan isi Accu ke Register Control                |
| Cycle end less                                        |
|            Isi Accu dengan data 01                    |
|            keluarkan isi Accu ke port A               |
|            Tunda Waktu                                |
|            Isi Accu dengan data 02                    |
|            Keluarkan isi Accu ke port A               |
|            Tunda Waktu                                |
|            Isi Accu dengan data 04                    |
|            Keluarkan isi Accu ke port A               |
|            Tunda Waktu                                |
|            Isi Accu dengan data 08                    |
|            Keluarkan isi Accu ke port A               |
|            Tunda Waktu                                |
|            Isi Accu dengan data 10                    |
|            Keluarkan isi Accu ke port A               |
|            Tunda Waktu                                |
|            Isi Accu dengan data 20                    |
|            Keluarkan isi Accu ke port A               |
|            Tunda Waktu                                |
|            Isi Accu dengan data 40                    |
|            Keluarkan isi Accu ke port A               |
|            Tunda Waktu                                |
|            Isi Accu dengan data 80                    |
|            Keluarkan isi Accu ke port A               |
|            Tunda Waktu                                |
| Isi Accu dengan data 00                               |
| Keluarkan isi Accu ke port A                          |
| Akhiri program                                        |

Subroutine 1A00

| Isi Pas Register HL = FF FF                        |
|----------------------------------------------------|
| H = 0                                              |
|            L = 0                                   |
|                     Kurangi denga 1 isi Register L |
|            Kurangi dengan 1 isi Register H         |
| RET UNC                                            |

Program Structure

| Alamat     | Assembly      | Mesin    |
|------------|---------------|----------|
| 1800       | LDA, 80       | 3E 80    |
| 1802       | OUT (43), A   | D3 43    |
| 1804       | NOP           | 00       |
| 1805       | LDA, 01       | 3E 01    |
| 1807       | OUT (40), A   | D3 40    |
| 1809       | CALL UNC 1A00 | CD 00 1A |
| 180B       | LDA, 02       | 3E 02    |
| 180E       | OUT (40), A   | D3 40    |
| 1810       | CALL UNC 1A00 | CD 00 1A |
| 1812       | LDA, 04       | 3E 04    |
| 1815       | OUT (40), A   | D3 40    |
| 1817       | CALL UNC 1A00 | CD 00 1A |
| 1819       | LDA, 08       | 3E 08    |
| 181C       | OUT (40), A   | D3 40    |
| 181E       | CALL UNC 1A00 | CD 00 1A |
| 1820       | LDA, 10       | 3E 10    |
| 1823       | OUT (40), A   | D3 40    |
| 1825       | CALL UNC 1A00 | CD 00 1A |
| 1827       | LDA, 20       | 3E 20    |
| 182A       | OUT (40), A   | D3 40    |
| 182C       | CALL UNC 1A00 | CD 00 1A |
| 182D       | LDA, 40       | 3E 40    |
| 1831       | OUT (40), A   | D3 40    |
| 1833       | CALL UNC 1A00 | CD 00 1A |
| 1835       | LDA, 80       | 3E 80    |
| 1838       | OUT (40), A   | D3 40    |
| 183A       | JPNC 1804     | C3 04 18 |
| SUBROUTINE |               |          |
| 1A00       | LDHL, FF FF   | 21 FF FF |
| 1A03       | NOP           | 00       |
| 1A04       | NOP           | 00       |
| 1A05       | DEC L         | 2D       |
| 1A06       | JPNZ 1A04     | C2 04 18 |
| 1A09       | DEC H         | 25       |
| 1A0A       | JPNZ 1A03     | C2 03 18 |
| 1A0D       | RET UNC       | C9       |

METHOD 2

Algorithm Structure

| Isi Accu dengan data kendali port A            |
|------------------------------------------------|
| Keluarkan isi Accu ke Register Control         |
| Cycle end less                                 |
|            A = 01                              |
|            B = 08                              |
|                       B = 0                    |
|                                  OUT (40) A    |
|                                  Tunda Waktu   |
|                                  A = A+A = SLA |
|                       DEC B                    |

Subroutine 1A00

| Isi Pas Register HL = FF FF                        |
|----------------------------------------------------|
| H = 0                                              |
|            L = 0                                   |
|                     Kurangi denga 1 isi Register L |
|            Kurangi dengan 1 isi Register H         |
| RET UNC                                            |

Program Structure

| Alamat     | Assembly      | Mesin    |
|------------|---------------|----------|
| 1800       | LDA, 80       | 3E 80    |
| 1802       | OUT (43), A   | D3 43    |
| 1804       | NOP           | 00       |
| 1805       | LDA, 01       | 3E 01    |
| 1807       | LDB, 07       | 06 07    |
| 1809       | NOP           | 00       |
| 180A       | OUT (40), A   | D3 40    |
| 180C       | CALL UNC 1A00 | CD 00 1A |
| 180F       | ADD A         | 87       |
| 1810       | DEC B         | 05       |
| 1811       | JPNZ 1809     | C2 09 18 |
| 1814       | JPUNC 1804    | C3 04 18 |
| SUBROUTINE |               |          |
| 1A00       | LDHL, FF FF   | 21 FF FF |
| 1A 03      | NOP           | 00       |
| 1A 04      | NOP           | 00       |
| 1A05       | DEC L         | 2D       |
| 1A06       | JPNZ 1A04     | C2 04 18 |
| 1A09       | DEC H         | 25       |
| 1A0A       | JPNZ 1A03     | C2 03 18 |
| 1A0D       | RET UNC       | C9       |

Hope this is useful & happy learning!

Traffic Light Assembly & Machine Programming

Traffic Light 1

Lamp Duration Table

Binary to Hexadecimal Conversion Table

| Waktu | Jalan D |     |     | Jalan C |     |     | Jalan B |     |     | Jalan A |     |     | Data            |
|-------|---------|-----|-----|---------|-----|-----|---------|-----|-----|---------|-----|-----|-----------------|
|       | PB5     | PB4 | PB3 | PB2     | PB1 | PB0 | PA5     | PA4 | PA3 | PA2     | PA1 | PA0 |                 |
|       |         |     |     |         |     |     |         |     |     |         |     |     |                 |
| 0-5   | 1       | 0   | 0   | 1       | 0   | 0   | 1       | 0   | 0   | 0       | 0   | 1   | PA = 21 , PB=24 |
| 5-7   | 1       | 0   | 0   | 1       | 0   | 0   | 1       | 0   | 0   | 0       | 1   | 0   | PA = 22 , PB=24 |
| 7-12  | 1       | 0   | 0   | 1       | 0   | 0   | 0       | 0   | 1   | 1       | 0   | 0   | PA = 0C , PB=24 |
| 12-14 | 1       | 0   | 0   | 1       | 0   | 0   | 0       | 1   | 0   | 1       | 0   | 0   | PA = 14 , PB=24 |
| 14-19 | 1       | 0   | 0   | 0       | 0   | 1   | 1       | 0   | 0   | 1       | 0   | 0   | PA = 24 , PB=21 |
| 19-21 | 1       | 0   | 0   | 0       | 1   | 0   | 1       | 0   | 0   | 1       | 0   | 0   | PA = 24 , PB=22 |
| 21-26 | 0       | 0   | 1   | 1       | 0   | 0   | 1       | 0   | 0   | 1       | 0   | 0   | PA = 24 , PB=0C |
| 26-28 | 0       | 1   | 0   | 1       | 0   | 0   | 1       | 0   | 0   | 1       | 0   | 0   | PA = 24 , PB=14 |

Algorithm Structure and Assembly

| Isi Accu dengan kendali port A = Port B = OUT, 80h |
|----------------------------------------------------|
| Keluarkan isi Accu ke Register Control             |
| Cycle End Less                                     |
|            LDE, 05                                 |
|            E = 0                                   |
|                       LDA, 21                      |
|                       OUT (40), A                  |
|                       LDA, 24                      |
|                       OUT (41), A                  |
|                       Tunda Waktu                  |
|                       DEC E                        |
|            LDE, 02h                                |
|            E = 0                                   |
|                       LDA, 22                      |
|                       OUT (40), A                  |
|                       LDA, 24                      |
|                       OUT (41), A                  |
|                       Tunda Waktu                  |
|                       DEC E                        |
|            LDE, 05h                                |
|            E = 0                                   |
|                       LDA, 0C                      |
|                       OUT (40), A                  |
|                       LDA, 24                      |
|                       OUT (41), A                  |
|                       Tunda Waktu                  |
|                       DEC E                        |
|            LDE, 02h                                |
|            E = 0                                   |
|                       LDA, 14                      |
|                       OUT (40), A                  |
|                       LDA, 24                      |
|                       OUT (41), A                  |
|                       Tunda Waktu                  |
|                       DEC E                        |
|            LDE, 05h                                |
|            E = 0                                   |
|                       LDA, 24                      |
|                       OUT (40), A                  |
|                       LDA, 21                      |
|                       OUT (41), A                  |
|                       Tunda Waktu                  |
|                       DEC E                        |
|            LDE, 02h                                |
|            E = 0                                   |
|                       LDA, 24                      |
|                       OUT (40), A                  |
|                       LDA, 22                      |
|                       OUT (41), A                  |
|                       Tunda Waktu                  |
|                       DEC E                        |
|            LDE, 05h                                |
|            E = 0                                   |
|                       LDA, 24                      |
|                       OUT (40), A                  |
|                       LDA, 0C                      |
|                       OUT (41), A                  |
|                       Tunda Waktu                  |
|                       DEC E                        |
|            LDE, 02h                                |
|            E = 0                                   |
|                       LDA, 24                      |
|                       OUT (40), A                  |
|                       LDA, 14                      |
|                       OUT (41), A                  |
|                       Tunda Waktu                  |
|                       DEC E                        |

Subroutine

| Isi Pas Register HL = FF FF                        |
|----------------------------------------------------|
| H = 0                                              |
|            L = 0                                   |
|                     Kurangi denga 1 isi Register L |
|            Kurangi dengan 1 isi Register H         |
| RET UNC                                            |

Program Structure

| Alamat     | Assembly      | Mesin    |
|------------|---------------|----------|
| 1800       | LDA, 80       | 3E 80    |
| 1802       | OUT (43), A   | D3 43    |
| 1804       | NOP           | 00       |
| 1805       | LDE, 05       | 1E 05    |
| 1807       | NOP           | 00       |
| 1808       | LDA, 21       | 3E 21    |
| 180A       | OUT (40), A   | D3 40    |
| 180C       | LDA, 24       | 3E 24    |
| 180E       | OUT (41), A   | D3 41    |
| 1810       | CALL UNC 1A00 | CD 00 1A |
| 1813       | DEC E         | 1D       |
| 1814       | JPNZ 1807     | C2 07 18 |
| 1817       | LDE, 02       | 1E 02    |
| 1819       | NOP           | 00       |
| 181A       | LDA, 22       | 3E 22    |
| 181C       | OUT (40), A   | D3 40    |
| 181E       | LDA, 24       | 3E 24    |
| 1820       | OUT (41), A   | D3 41    |
| 1822       | CALL UNC 1A00 | CD 00 1A |
| 1825       | DEC E         | 1D       |
| 1826       | JPNZ 1819     | C2 19 18 |
| 1829       | LDE, 05       | 1E 05    |
| 182B       | NOP           | 00       |
| 182C       | LDA, 0C       | 3E 0C    |
| 182E       | OUT (40), A   | D3 40    |
| 1830       | LDA, 24       | 3E 24    |
| 1832       | OUT (41), A   | D3 41    |
| 1834       | CALL UNC 1A00 | CD 00 1A |
| 1837       | DEC E         | 1D       |
| 1838       | JPNZ 182B     | C2 2B 18 |
| 183B       | LDE, 02       | 1E 02    |
| 183D       | NOP           | 00       |
| 183E       | LDA, 14       | 3E 14    |
| 1840       | OUT (40), A   | D3 40    |
| 1842       | LDA, 24       | 3E 24    |
| 1844       | OUT (41), A   | D3 41    |
| 1846       | CALL UNC 1A00 | CD 00 1A |
| 1849       | DEC E         | 1D       |
| 184A       | JPNZ 183D     | C2 3D 18 |
| 184D       | LDE, 05       | 1E 05    |
| 184F       | NOP           | 00       |
| 1850       | LDA, 24       | 3E 24    |
| 1852       | OUT (40), A   | D3 40    |
| 1854       | LDA, 21       | 3E 21    |
| 1856       | OUT (41), A   | D3 41    |
| 1858       | CALL UNC 1A00 | CD 00 1A |
| 185B       | DEC E         | 1D       |
| 185C       | JPNZ 184F     | C2 4F 18 |
| 185F       | LDE, 02       | 1E 02    |
| 1861       | NOP           | 00       |
| 1862       | LDA, 24       | 3E 24    |
| 1864       | OUT (40), A   | D3 40    |
| 1866       | LDA, 22       | 3E 22    |
| 1868       | OUT (41), A   | D3 41    |
| 186A       | CALL UNC 1A00 | CD 00 1A |
| 186D       | DEC E         | 1D       |
| 186E       | JPNZ 1861     | C2 61 18 |
| 1871       | LDE, 05       | 1E 05    |
| 1873       | NOP           | 00       |
| 1874       | LDA, 24       | 3E 24    |
| 1876       | OUT (40), A   | D3 40    |
| 1878       | LDA, 0C       | 3E 0C    |
| 187A       | OUT (41), A   | D3 41    |
| 187C       | CALL UNC 1A00 | CD 00 1A |
| 187F       | DEC E         | 1D       |
| 1880       | JPNZ 1873     | C2 73 18 |
| 1883       | LDE, 02       | 1E 02    |
| 1885       | NOP           | 00       |
| 1886       | LDA, 24       | 3E 24    |
| 1888       | OUT (40), A   | D3 40    |
| 188A       | LDA, 14       | 3E 14    |
| 188C       | OUT (41), A   | D3 41    |
| 188E       | CALL UNC 1A00 | CD 00 1A |
| 1891       | DEC E         | 1D       |
| 1892       | JPNZ 1885     | C2 85 18 |
| 1895       | JPUNC 1804    | C3 04 18 |
| SUBROUTINE |               |          |
| 1A00       | LDHL, FF FF   | 21 FF FF |
| 1A 03      | NOP           | 00       |
| 1A 04      | NOP           | 00       |
| 1A05       | DEC L         | 2D       |
| 1A06       | JPNZ 1A04     | C2 04 18 |
| 1A09       | DEC H         | 25       |
| 1A0A       | JPNZ 1A03     | C2 03 18 |
| 1A0D       | RET UNC       | C9       |

Traffic Light 2

Binary to Hexadecimal Conversion Table

| Waktu | Jalan D |     |     | Jalan C |     |     | Jalan B |     |     | Jalan A |     |     | Data            |
|-------|---------|-----|-----|---------|-----|-----|---------|-----|-----|---------|-----|-----|-----------------|
|       | PB5     | PB4 | PB3 | PB2     | PB1 | PB0 | PA5     | PA4 | PA3 | PA2     | PA1 | PA0 |                 |
|       |         |     |     |         |     |     |         |     |     |         |     |     |                 |
| 0-5   | 1       | 0   | 0   | 1       | 0   | 0   | 1       | 0   | 0   | 0       | 0   | 1   | PA = 21 , PB=24 |
| 5-7   | 1       | 0   | 0   | 1       | 0   | 0   | 1       | 0   | 0   | 0       | 1   | 0   | PA = 22 , PB=24 |
| 7-12  | 1       | 0   | 0   | 1       | 0   | 0   | 0       | 0   | 1   | 1       | 0   | 0   | PA = 0C , PB=24 |
| 12-14 | 1       | 0   | 0   | 1       | 0   | 0   | 0       | 1   | 0   | 1       | 0   | 0   | PA = 14 , PB=24 |
| 14-19 | 1       | 0   | 0   | 0       | 0   | 1   | 1       | 0   | 0   | 1       | 0   | 0   | PA = 24 , PB=21 |
| 19-21 | 1       | 0   | 0   | 0       | 1   | 0   | 1       | 0   | 0   | 1       | 0   | 0   | PA = 24 , PB=22 |
| 21-26 | 0       | 0   | 1   | 1       | 0   | 0   | 1       | 0   | 0   | 1       | 0   | 0   | PA = 24 , PB=0C |
| 26-28 | 0       | 1   | 0   | 1       | 0   | 0   | 1       | 0   | 0   | 1       | 0   | 0   | PA = 24 , PB=14 |
| 28-33 | 0       | 1   | 0   | 0       | 1   | 0   | 0       | 1   | 0   | 0       | 1   | 0   | PA = 12 , PB=12 |

Algorithm Structure and Assembly Program

| Isi Accu dengan kendali Port A = Port B =  OUT, 80h |
|-----------------------------------------------------|
| Keluarkan isi Accu ke Register Control              |
| Cycle End Less                                      |
|            LDH, 0F                                  |
|            H = 0                                    |
|            LDE, 05h                                 |
|            E = 0                                    |
|                       LDA, 21                       |
|                       OUT (40), A                   |
|                       LDA, 24                       |
|                       OUT (41), A                   |
|                       Tunda Waktu                   |
|                       DEC E                         |
|            LDE, 02h                                 |
|            E = 0                                    |
|                       LDA, 22                       |
|                       OUT (40), A                   |
|                       LDA, 24                       |
|                       OUT (41), A                   |
|                       Tunda Waktu                   |
|                       DEC E                         |
|            LDE, 05h                                 |
|            E = 0                                    |
|                       LDA, 0C                       |
|                       OUT (40), A                   |
|                       LDA, 24                       |
|                       OUT (41), A                   |
|                       Tunda Waktu                   |
|                       DEC E                         |
|            LDE, 02h                                 |
|            E = 0                                    |
|                       LDA, 14                       |
|                       OUT (40), A                   |
|                       LDA, 24                       |
|                       OUT (41), A                   |
|                       Tunda Waktu                   |
|                       DEC E                         |
|            LDE, 05h                                 |
|            E = 0                                    |
|                       LDA, 24                       |
|                       OUT (40), A                   |
|                       LDA, 21                       |
|                       OUT (41), A                   |
|                       Tunda Waktu                   |
|                       DEC E                         |
|            LDE, 02h                                 |
|            E = 0                                    |
|                       LDA, 24                       |
|                       OUT (40), A                   |
|                       LDA, 22                       |
|                       OUT (41), A                   |
|                       Tunda Waktu                   |
|                       DEC E                         |
|            LDE, 05h                                 |
|            E = 0                                    |
|                       LDA, 24                       |
|                       OUT (40), A                   |
|                       LDA, 0C                       |
|                       OUT (41), A                   |
|                       Tunda Waktu                   |
|                       DEC E                         |
|            LDE, 02h                                 |
|            E = 0                                    |
|                       LDA, 24                       |
|                       OUT (40), A                   |
|                       LDA, 12                       |
|                       OUT (41), A                   |
|                       Tunda Waktu                   |
|                       DEC E                         |
|            LDE, 05h                                 |
|            E = 0                                    |
|                       LDA, 12                       |
|                       OUT (40), A                   |
|                       OUT (41), A                   |
|                       Tunda Waktu                   |
|                       LDA, 00                       |
|                       OUT (40), A                   |
|                       OUT (41), A                   |
|                       DEC E                         |

Hope this is useful & happy learning!

Comment 1

SITE ADMINISTRATOR Oct 30, 2014, 10:49:00 nice and creative article bro. Doesn't it use 8080/8085 assembler bro?

Thanks bro for replying. If you have entered my blog, look for it in the right sidebar/label "computer", there it is. Or you can go directly here

Response 1

Thanks bro, thanks for the info too... but it seems like the assembler book isn't there, after stopping by...

Assembly Programming & Ring Counter Machine


Illustration of Ring Counter Variation

Algorithm / Assembly Structure

| LDA, 80                           |
|-----------------------------------|
| OUT (43), A                       |
| Cycle End Less                    |
|          LDA, 18                  |
|          OUT (41), A              |
|                       Tunda Waktu |
|          LDA, 24                  |
|          OUT (41), A              |
|                       Tunda Waktu |
|          LDA, 42                  |
|          OUT (41), A              |
|                       Tunda Waktu |
|          LDA, A5                  |
|          OUT (41), A              |
|                       Tunda Waktu |
|          LDA, 00                  |
|          OUT (41), A              |
|                       Tunda Waktu |
|          LDA, 01                  |
|          OUT (42), A              |
|          LDA, 80                  |
|          OUT (40), A              |
|                       Tunda Waktu |
|          LDA, 02                  |
|          OUT (42), A              |
|          LDA, 40                  |
|          OUT (41), A              |
|                       Tunda Waktu |
|          LDA, 04                  |
|          OUT (42), A              |
|          LDA, 20                  |
|          OUT (40), A              |
|                       Tunda Waktu |
|          LDA, 08                  |
|          OUT (42), A              |
|          LDA, 10                  |
|          OUT (40), A              |
|                       Tunda Waktu |
|          LDA, 10                  |
|          OUT (42), A              |
|          LDA, 08                  |
|          OUT (40), A              |
|                       Tunda Waktu |
|          LDA, 20                  |
|          OUT (42), A              |
|          LDA, 04                  |
|          OUT (40), A              |
|                       Tunda Waktu |
|          LDA, 40                  |
|          OUT (42), A              |
|          LDA, 02                  |
|          OUT (40), A              |
|                       Tunda Waktu |
|          LDA, 80                  |
|          OUT (42), A              |
|          LDA, 01                  |
|          OUT (40), A              |
|                       Tunda Waktu |
|          LDA, 00                  |
|          OUT (42), A              |
|          LDA, 00                  |
|          OUT (40), A              |
|                       Tunda Waktu |
|          LDA, ff                  |
|          OUT (40), A              |
|          OUT (41), A              |
|          OUT (42), A              |
|                       Tunda Waktu |
|          LDA, 00                  |
|          OUT (40), A              |
|          OUT (41), A              |
|          OUT (42), A              |
|                       Tunda Waktu |
|          LDA, ff                  |
|          OUT (40), A              |
|          OUT (41), A              |
|          OUT (42), A              |
|                       Tunda Waktu |
|          LDA, 00                  |
|          OUT (40), A              |
|          OUT (41), A              |
|          OUT (42), A              |
|                       Tunda Waktu |

Subroutine

| Isi Pas Register HL = FF FF                        |
|----------------------------------------------------|
| H = 0                                              |
|            L = 0                                   |
|                     Kurangi denga 1 isi Register L |
|            Kurangi dengan 1 isi Register H         |
| RET UNC                                            |

Program Structure

| Alamat     | Assembly      | Mesin    |
|------------|---------------|----------|
| 1800       | LDA, 80       | 3E 80    |
| 1802       | OUT (43), A   | D3 43    |
| 1804       | NOP           | 00       |
| 1805       | LDA, 18       | 3E 18    |
| 1807       | OUT (41), A   | D3 41    |
| 1809       | CALL UNC 1A00 | CD 00 1A |
| 180C       | LDA, 24       | 3E 24    |
| 180E       | OUT (41), A   | D3 41    |
| 1810       | CALL UNC 1A00 | CD 00 1A |
| 1813       | LDA, 42       | 3E 42    |
| 1815       | OUT (41), A   | D3 41    |
| 1817       | CALL UNC 1A00 | CD 00 1A |
| 181A       | LDA, A5       | 3E A5    |
| 181C       | OUT (41), A   | D3 41    |
| 181E       | CALL UNC 1A00 | CD 00 1A |
| 1821       | LDA, 00       | 3E 00    |
| 1823       | OUT (41), A   | D3 41    |
| 1825       | CALL UNC 1A00 | CD 00 1A |
| 1828       | LDA, 01       | 3E 01    |
| 182A       | OUT (42), A   | D3 42    |
| 182C       | LDA, 80       | 3E 80    |
| 182E       | OUT (40), A   | D3 40    |
| 1830       | CALL UNC 1A00 | CD 00 1A |
| 1833       | LDA, 02       | 3E 02    |
| 1835       | OUT (42), A   | D3 42    |
| 1837       | LDA, 40       | 3E 40    |
| 1839       | OUT (40), A   | D3 40    |
| 183B       | CALL UNC 1A00 | CD 00 1A |
| 183E       | LDA, 04       | 3E 04    |
| 1840       | OUT (42), A   | D3 42    |
| 1842       | LDA, 20       | 3E 20    |
| 1844       | OUT (40), A   | D3 40    |
| 1846       | CALL UNC 1A00 | CD 00 1A |
| 1849       | LDA, 08       | 3E 08    |
| 184B       | OUT (42), A   | D3 42    |
| 184D       | LDA, 10       | 3E 10    |
| 184F       | OUT (40), A   | D3 40    |
| 1851       | CALL UNC 1A00 | CD 00 1A |
| 1854       | LDA, 10       | 3E 10    |
| 1856       | OUT (42), A   | D3 42    |
| 1858       | LDA, 08       | 3E 08    |
| 1860       | OUT (40), A   | D3 40    |
| 1862       | CALL UNC 1A00 | CD 00 1A |
| 1865       | LDA, 20       | 3E 20    |
| 1867       | OUT (42), A   | D3 42    |
| 1869       | LDA, 04       | 3E 04    |
| 186B       | OUT (40), A   | D3 40    |
| 186D       | CALL UNC 1A00 | CD 00 1A |
| 1870       | LDA, 40       | 3E 40    |
| 1872       | OUT (42), A   | D3 42    |
| 1874       | LDA, 02       | 3E 02    |
| 1876       | OUT (40), A   | D3 40    |
| 1878       | CALL UNC 1A00 | CD 00 1A |
| 187B       | LDA, 80       | 3E 80    |
| 187D       | OUT (42), A   | D3 42    |
| 187F       | LDA, 01       | 3E 01    |
| 1881       | OUT (40), A   | D3 40    |
| 1883       | CALL UNC 1A00 | CD 00 1A |
| 1886       | LDA, 00       | 3E 00    |
| 1888       | OUT (42), A   | D3 42    |
| 188A       | OUT (40), A   | D3 40    |
| 188C       | CALL UNC 1A00 | CD 00 1A |
| 188F       | LDA, FF       | 3E FF    |
| 1891       | OUT (40), A   | D3 40    |
| 1893       | OUT (41), A   | D3 41    |
| 1895       | OUT (42), A   | D3 42    |
| 1897       | CALL UNC 1A00 | CD 00 1A |
| 189A       | LDA, 00       | 3E 00    |
| 189C       | OUT (40), A   | D3 40    |
| 189E       | OUT (41), A   | D3 41    |
| 18A0       | OUT (42), A   | D3 42    |
| 18A2       | CALL UNC 1A00 | CD 00 1A |
| 18A5       | LDA, FF       | 3E FF    |
| 18A7       | OUT (40), A   | D3 40    |
| 18A9       | OUT (41), A   | D3 41    |
| 18AB       | OUT (42), A   | D3 42    |
| 18AD       | CALL UNC 1A00 | CD 00 1A |
| 18B0       | LDA, 00       | 3E 00    |
| 18B2       | OUT (40), A   | D3 40    |
| 18B4       | OUT (41), A   | D3 41    |
| 18B6       | OUT (42), A   | D3 42    |
| 18B8       | CALL UNC 1A00 | CD 00 1A |
| SUBROUTINE |               |          |
| 1A00       | LDHL, FF FF   | 21 FF FF |
| 1A 03      | NOP           | 00       |
| 1A 04      | NOP           | 00       |
| 1A05       | DEC L         | 2D       |
| 1A06       | JPNZ 1A04     | C2 04 18 |
| 1A09       | DEC H         | 25       |
| 1A0A       | JPNZ 1A03     | C2 03 18 |
| 1A0D       | RET UNC       | C9       |

Hope this is useful & happy learning!

Example of 7 Segment Display Assembly Program af

Data Pointer (DPTR), is user access to registers that are only available on the 8051 16-bit (2-byte) microcontroller.

DPTR, as the name suggests, is used to point to data. It is used by a number of commands that allow the 8051 to access external memory. When the 8051 accesses external memory, the external memory that is accessed is the address pointed to by DPTR.

Meanwhile, DPTR is also often used to point to data in external memory, many programmers take advantage of the fact that this is the only way provided by 16-bit registers. It is also often used to store 2-byte values ​​that have nothing to do with memory locations.

Source Code:

$MOD51 ; This includes 8051 definitions for the Metalink assembler

; Please insert your code here.

;- BAB3_08.ASM -------------------------------------------------------------------
;
; Menghidupkan display LED 7 segment untuk menampilkan huruf a s/d F
; cara 2 : data diambil dari alamat larik (array) data, program jadi lebih pendek
; author : www.gatewan.com ( Debugging has been completed on 21/11/2016 )
; DPTR  : ***Load data pointer with a 16-bit constant***
;---------------------------------------------------------------------------------

Mulai:
 Mov R2,#6h       ; jumlah huruf yg akan ditampilkan
 MOV DPTR,#Huruf  ; register DPTR menunjuk pada lokasi awal data
Nextdata:
 Clr A            ; persiapkan akumulator
 Movc A,@A+DPTR   ; salin isi lokasi yg ditunjuk A+DPTR ke A
 Mov P0,A         ; keluarkan data A ke port 0
 Inc DPTR         ; ke lokasi data berikutnya
 Acall Delay      ; lakukan penundaan sesaat...
 Djnz R2,Nextdata ; R2=R2-1, jika R2 <> 0 ulangi lagi
 Sjmp Mulai       ; ulangi lagi dari awal...

;-subrutin DELAY------------------------------------------------------------------
;
; subrutin ini hanya sekedar melakukan penundaan sesaat dengan cara
; mengulangi proses (pengurangan isi register) hingga dicapai suatu
; kondisi tertentu
;
;---------------------------------------------------------------------------------
Delay: Mov R0,#2h  ; Isi Register R0 dengan 2 (2x ulang)
Delay1: Mov R1,#1h ; Isi Register R1 dengan 2 (25x ulang)
Delay2: Mov R2,#0  ; Isi register R2 dengan 0 (26x ulang)
 Djnz R2,$
 Djnz R1,Delay2
 Djnz R0,Delay1
 Ret

;---------------------------------------------------------------------------------
; Lokasi larik data
; berisi kode-kode untuk menghidupkan 7-segmen: huruf a s/d f secara berturutan
;---------------------------------------------------------------------------------
Huruf:
 DB 088h,83h,0C6h,0A1h,86h,8Eh

END

Demo:

https://youtu.be/_aTEJupod_k

DOWNLOAD SCHEMATIC (102KB)

Reference

  • ftp://ftp.ti.com/pub/data_acquisition/MSC_CD-ROM/8051_Tutorial/tutbregs.html

Assembly Programming Number Types

In programming with assembler language, various types of numbers can be used. The types of numbers that can be used are: Binary, octave, decimal and hexadecimal numbers. Understanding these types of numbers is important, because it will greatly help us in real programming.


Types of Numbers in Assembly Programming

1. Binary Numbers

Actually all numbers, data and programs themselves will be translated by the computer into binary form. So defining data with any type of number (Decimal, octave and hexadecimal) will always be translated by the computer into binary form.

Binary numbers are numbers that only consist of 2 possibilities (based on two), namely 0 and 1. Because it is based on 2, the conversion to decimal form is done by multiplying the Nth term by 2N. For example: binary numbers,

01112 = (0 X 23) + (1 X 22) + (1 X 21) + (1 X 20) = 710

2. Decimal Numbers

Of course, this type of number is familiar to all of us. Decimal numbers are the most widely used type of numbers in everyday life, so most people are familiar with them.

Decimal numbers are numbers consisting of 10 digits (base 10), namely numbers 0-9. With this base ten, a number can be described by the power of ten. For example, in the numbers;

12310 = (1 X 102) + (2 X 101) + (1 X 100)

3. Octal Numbers

Octal numbers are numbers with a base of 8, meaning that the numbers used are only between 0-7. Similar to other types of numbers, an octal number can be converted into decimal form by multiplying the Nth term by 8N. For example, the numbers;

128 = (1 X 81) + (2 X 80) = 1010

4. Hexadecimal numbers

Hexadecimal numbers are numbers based on 16. The numbers used are:

0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F.

In assembler programming, this type of number can be said to be the most widely used. This is because it is easy to convert this number with other numbers, especially with binary and decimal numbers. Because it is based on 16, then 1 number in hexadecimal will use 4 bits.

5. Marked & Unmarked Biangan

In assembler, numbers are divided into 2, namely signed and unsigned numbers. Signed numbers are numbers that have the meaning plus (+) and minus (-), for example the numbers 17 and -17. In unsigned numbers, negative numbers (which contain the sign '-') are not recognized. So the number -17 will not be recognized as the number -17, but as another number.

When is a number treated as a signed number and not? The assembler will always look at the Sign Flag, if this flag has a value of 0, then the number will be treated as an unsigned number, conversely if this flag has a value of 1, then the number will be treated as a signed number.

In signed numbers, the last bit (bit 16) is used as a plus (+) or minus (-) sign. If the last bit has a value of 1, it means the number is a negative number, conversely if the last bit has a value of 0, it means the number is a positive number.

| BILANGAN  |                |          |
|-----------|----------------|----------|
| Biner     | Tidak Bertanda | Bertanda |
| 0000 0101 | + 5            | + 5      |
| 0000 0100 | + 4            | + 4      |
| 0000 0011 | + 3            | + 3      |
| 0000 0010 | + 2            | + 2      |
| 0000 0001 | + 1            | + 1      |
| 0000 0000 | 0              | 0        |
| 1111 1111 | + 255          | - 1      |
| 1111 1110 | + 254          | - 2      |
| 1111 1101 | + 253          | - 3      |
| 1111 1100 | + 252          | - 4      |
| 1111 1011 | + 251          | - 5      |
| 1111 1010 | + 250          | - 6      |

Assembly Programming Basics

1. Text Editor

To write the source file for assembly program you can use various editors, for example SideKick, WordStar and Word Perfect. The typed source file must be an ASCII file, this file can be generated through WordStar with the file 'NON DOCUMENT', or with SideKick.

To make sure that the source file you created is an ASCII file, you can try typing the Type command in A>. If the file seen with the type command is exactly the same as the one you typed in the editor, without any additional random characters, then the file is an ASCII file. The source file for assembly must have the extension .ASM.

2. Compiler

The ASCII source file that you have typed needs to be compiled into an object file with the extension .OBJ. From this object file, it can later be converted into an .EXE or .COM file.

To compile a source file, for example the COBA.ASM file into an object file with the .OBJ extension, you can use the TASM.EXE file by typing:


Turbo Assembler

3. Linking

Object files that have been created with TASM cannot be executed directly. To create an object file into an executable file (.COM or .EXE extension) you can use the TLINK.EXE file.

If the source program you created is in EXE format, then to create a file with the EXE extension you can type:

C:\>tlink coba
Turbo Link Version 3.0 Copyright (c) 1987,
1990 Borland International

If the source program created is a COM file, then you can type:

C:\>tlink/t coba
Turbo Link Version 3.0 Copyright (c) 1987,
1990 Borland International

4. Differences between *com & *exe programs

Programs with the extensions .COM and .EXE have several striking differences, including:

COM PROGRAM:

  • Shorter than EXE file
  • Faster than EXE files
  • Can only use 1 segment
  • Maximum file size 64 KB (size of one segment)
  • It is difficult to access data or procedures located in other segments.
  • The first 100h bytes are the PSP (Program Segment Prefix) of the program.
  • Can be made with DEBUG.

EXE PROGRAM:

  • Longer than COM files
  • Slower than COM files
  • Can use more than 1 segment
  • Unlimited file size according to memory size.
  • Easy to access data or procedures in other segments.
  • Cannot be created with DEBUG

5. Number Form

The assembler allows the use of several forms of numbers, namely:

5.1 DECIMAL

To write numbers in decimal form, you can use the 'D' symbol at the end of the number or you can also leave no symbol at all, for example: 298D or just 298.

5.2 BINARY

To write numbers in binary form (0..1), you must add a 'B' at the end of the number, for example: 01100111B.

5.3 HEXADESIMAL

To write a number in hexadecimal form (0..9,A..F), you must add the 'H' symbol at the end of the number. It should be noted that if the first number of hexa is a character (A..F) then a zero must be added in front of it. If this is not done, the assembler will consider it as a label, not as a hexa value. Examples of correct writing: 0A12H, 2A02H.

5.4 CHARACTERS

Writing characters or strings is enclosed in double quotation marks (") or single quotation marks ('), Example: ' This is a character '.

6. Label

You can define a label with the condition that the end of the label name must be a colon ( 🙂. Label naming can be done using:

  • Letters: A..Z (Uppercase and lowercase letters are not distinguished)
  • Number: 0..9
  • Special characters: @ . _ $

The name on the label must not contain spaces and be preceded by a number. Example of correct label writing: start: MOV CX,7. The longest label name that the assembler can recognize is 31 characters.

7. Comments

To provide comments on the source file, use the ';' symbol. Anything written behind the ';' symbol will be considered a comment, Example: start: MOV BX,7 ; give the value 7 to BX.

8. MOV command

The MOV command is used to copy a value or number to a register, variable or memory. The syntax for the MOV command is:

MOV Destination, Origin

For example:

MOV AL,9 ; masukkan nilai 9 pada AL.
MOV AH,AL ; nilai AL=9 dan AH=9
MOV AX,9 ; AX=AH+AL hingga AH=0 dan AL:=9

In the first line (MOV AL,9), we assign a value of 9 to the AL register. Then in the second line (MOV AH,AL) we copy the value of the AL register to AH. So after this operation the AL register will still have a value of 9, and the AH register will be the same value as AL or 9. In the third line (MOV AX,9), we assign the AX register a value of 9. Since AX consists of AH and AL, the AH register will have a value of 0, while AL will have a value of 9.

The MOV command will copy the value on the source to be inserted into the Destination, the source value is not changed. This is why MOV(E) will be translated here as copying, and not moving.

9. INT Command

In assembler programming, we will use interrupts a lot to help us in doing a job. To produce an interrupt, the INT command is used with the syntax:

INT NoInt

Where NoInt is the interrupt number to be generated. For example, if we want to generate interrupt 21h, we can write it as: INT 21h, then interrupt 21h will occur immediately.


Post a Comment

Previous Next

نموذج الاتصال