You are on page 1of 2

;

;
;
;

This YourName2.txt program marches the name "JOHN" across the


signboard using a better algorithm than was used in YourName.txt .
It is better because we replace a repeating section of code with
a subroutine (accessed via the LCALL mnemonic).

; To modify this program to march your own name across the signboard
; you will be aided by the following table of indices for all the
; alphabet letters:
; A B C D E F G H I J K L M N O P Q R S T U V W X Y Z blank
; 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
; Note that FontData.txt holds the image data for a blank (space)
; character at the very end of the alphabet.
LJMP Start

; Jump over the DB statements included from


; the "FontData.txt" file since DB statements
; hold data rather than executable instructions.

INCLUDE "FontData.txt"
Start:

MOV DPTR,#StartOfImageData
; We initialize the DPTR ("data pointer"), a 16 bit
; SFR ("special function register"), to point to
; the first column of font data (the first column
; of the letter 'A') in program memory. The DPTR
; register continues to hold this same value
; throughout this program.
MOV A,#9*8 ; The letter 'J' has alphabet index 9 (indices always
; start from 0) and hence the first column of font
; data for the letter 'J' is 9*8=72 bytes beyond
; the start of the font data (which is where DPTR
; points) in program memory.
LCALL Draw1Char
MOV

A,#14*8

; letter 'O' has alphabet index 14

LCALL Draw1Char
MOV

A,#7*8

; letter 'H' has alphabet index 7

LCALL Draw1Char
MOV

A,#13*8

; letter 'N' has alphabet index 13

LCALL Draw1Char
Done:

SJMP Done

Draw1Char:
; This is a subroutine which is responsible for outputting exactly 8
; columns (hence 1 character) of font data to the electric sign board.
; Before you call this subroutine initialize the ACC with the byte
; offset to the column data for the desired character. That is, if
; you want the letter 'C' output to the signboard then call this
; subroutine with ACC = 2 * 8 = 16.
; Within this subroutine we use R0 as a temporary storage location
; for the accumulator's value (we need this because the "MOVC A,@A+DPTR"

;
;
;
;
;

instruction keeps perturbing the accumulator). And we use the


R1 register to control the loop (that is, decide how many times
we iterate). Note that R0 is synonymous with data memory location 0
and R1 is synonymous with data memory location 1 (at least while
the 8051 is in its default configuration).
MOV

R0,A

MOV

R1,#0

CharLoop: MOV
MOVC
MOV
INC
INC
CJNE
RET

; preserve this starting column # since the


; upcoming "MOVC A,@A+DPTR" instruction
; replaces the value in the ACC
; we use R1 to control the looping

A,R0
; prepare for upcoming "MOVC A,@A+DPTR" instr
A,@A+DPTR ; the ACC now holds one column of font data
P0,A
; write that column to the sign board
R0
; advance to the next column
R1
; increment the loop counter
R1,#8,CharLoop
; we loop 8 times in order to output 8 columns

You might also like