Вы находитесь на странице: 1из 11

PART 3 ASSEMBLY LANGUAGE

CHAPTER 8 – PC ASSEMBLERs

• Microsoft Macro Assembler for PC

• Turbo Assemble - Borland • DOS/BIOS Functions

CHAPTER 8: MS/TURBO ASSEMBLER

8.1. Definitions:

• Assembler for an assembly language, a computer program to translate between lower- level representations of computer programs

• A full tool to create a Assembly Language Program (Assembler):

– An any standard Editor (ASCII) – Assembler:

• Checks syntax, error,…

• Replaces names of label, variable… real address, constant symbols – 1 pass • Converts Assembly Mnemonics to Object Code, 2 pass. • Links several modules become an executable file (.EXE file). This procedure is needed even program has one module • Option: Converts to .COM file : exe2bin

• Replaces names of label, variable… real address, constant symbols – 1 pass • Converts Assembly

8.2. DIRECTIVES – Pseudo OpCode

• Assembly Directives are instructions that are executed by the Assembler at assembly time, not by the CPU at run time. They can make the assembly of the program dependent on parameters input by the programmer, so that one program can be assembled different ways, perhaps for different applications. They also can be used to manipulate presentation of the program to make it easier for the programmer to read and maintain.

• PROC … ENDP DIRECTIVES:

– Are used to identify the start and end of procedure – The PROC follows name you give to procedure

– A term NEAR of FAR is used to specify type of procedure

– FE:

LED_CON … … LED_CON ENDP

PROC NEAR

– Caution: In MASM, main program is known a proc too

SEGMENT…ENDS DIRECTIVES

• To declare a logical segment is used

CODE SEGMENT … CODE ENDS

• PUBLIC directive to tell assembler that this segment may be put together with other segments named CODE from other modules when the modules are linked together.

CODE

SEGMENT

PUBLIC

DIRECTIVES

• END directives: is put after the last statement of a program to tell assebler that this is the end of program module. Assembler will ignore any statement after END directive.

• GROUP dir: is used to group the logical segments named after directive into one local group segment

DEFINE DATA DIRECTIVES

• DB - define byte: is used to declare a byte type variable or to set aside one or more storage locations of type byte in memory

Temp

DB

(?);

Not initialized

Name_Here

DB

‘BARACK OBAMA’; a string

LED_Table

DB

21, 45h, ‘C’, 345, (?);

DataStorage

DB

100h DUP (?); Not Init

• DW – Define word, DD – Define Double Word, DT – Define TenByte

• EQU: is used give a name to some value or symbol.

PA_Addr

EQU

300h…

… MOV DX,PA_Addr;

Simplified Segment Definition

• For more simple, some latter versions of Assembler accept some directives to declare segments:

.Stack

.Data

.Code

• These directives don’t need to combine the ENDS directives

CASE STUDY – LED BURNING

CASE STUDY – LED BURNING

EXERCISE: 6 x 7segment - LED interfacing

– PPI 8255:

• All ports are mode 0, PA and PC are output, PB is Input • Address PA is 0E0H, PB: 0E1H, PC: 0E2H and CR:

0E3H

• PA0: Serial Data • PA1: Serial Clock = rise edge • PA2: HC595 Latch = rise edge • PA3: Clear HC595 = 0 low pulse

– LEDs: 6 Common anode, 7 segment LEDs, driven by 74HC595 chips, Fig 2

Description: Suppose that • IO space, 0E0h to 0E3h. • The system is supported by BIOS

Description:

Suppose that

• IO space, 0E0h to 0E3h.

• The system is supported by BIOS and DOS functions for standard Input (Key board, Int 16h), Output (Screen) and terminate

• In this exercise, some PROCes and MACROes are used

• CONTENT: Read 6 number characters from Key Board, suppose that no user error in this phase. Convert these digits to BCD then convert to 7 Segment and display to 6 LED – the model display board with 74HC595.

;= = = = = = = = = .MODEL SMALL

DECLARING = = = = = = = = = = = = = = = = = = = = =

; Declaring model of program:

.STACK

64

; tiny/small/medium/large/huge/flat ; Stack Mem

.DATA

; !!! there is a dots front of logical segment

Table7Seg

DB

3FH, 06H, 5BH, 4FH, 66H, 6DH, 7DH, 07H, 7FH, 6FH ;

@7SegBuf

DB

; Table contains 10 bytes of 7 seg codes, 0 - 9 6 DUP (?) ; declaring 6 byte array variable, not ;initialized

BCD_Buf

DB

6 DUP (?) ; declaring an array 6 bytes, not initialized

; = = = = = = PROGRAM = = = = = = = = = = = = = = = = = = =

.CODE

; Program starts here

Chinh

PROC NEAR

; Main is named for program

MOV AX,@DATA

; Assigning logical data segment to ; physical DATA segment

MOV DS,AX

INIT_PPI

; inserting a macro here

Clear_595

; use macro to clear 6 LEDs to zeros

; = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

MOV BX, offset BCD_Buf; Read 6 digit ASCII from KB, convert to BCD

 

MOV CX,6

; and save to BCD_Buf

M1:

MOV AH,0

; Wait for character from Standard Input (Key Board)

INT 16H

; using the BIOS function, DOS’s available also

SUB AL,30H

; Convert ASCII to BCD

MOV [BX],AL

; saving BCD to BCD_Buf Array

INC BX

; Next digit

LOOP M1

; after 6 loops, 6 BCD num are located in BCD_Buff

; = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

 

CALL

BCD_7Seg ; Converting 6 bytes of un-package BCD to 7 segment

CALL SHIFT6BYTE IN AL,0E0h OR AL,00000100b OUT 0E0h,AL NOP

; Shifting to HC595 ; Displaying ; SET LATCH PULSE ; LEDs are turned on after

NOP

; Delay 2 machine cycles for Latch pulse is wide enough

AND AL,11111011b OUT 0E0h, AL

; RESET PULSE ;

; = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = MOV AH, 0

Int 16h

; Wait for key pressed to terminate

MOV AH,4CH ; Terminating an .exe file – a DOS function

Chinh

INT 21H

ENDP

; = = = = = = PROCEDURES AND MACROES ARE DECLARED HERE Init_PPI MACRO PUSH AX

MOV AL,10000010b OUT 0E3h,AL MOV AL,00001000b

; PA, PB, PC mode 0, PA, PC out, PB in ; Sending to PPI Control Register ; Un-Clear HC595

OUT 0E0h,AL ; Sending to HC595: data=0, Clk=0, latch=0, Clr=1

POP AX

;

Init_PPI ENDM

Clear_595

MACRO

IN AL,0E0h AND AL,11110111b

; Read PA ; Clear pins = 0

OUT 0E0h,AL

NOP

; Delay for 2 Machine cycles

NOP OR AL,00001000b OUT 0E0h,AL

; Un-clear HC595 ; Send to PA

Clear_595

ENDM

; = = = = = = = = = = = = = = = = = =

ShiftBIT MACRO BITT PUSH AX MOV AL,BITT OUT 0E0h,AL NOP OR AL, 00000010b

; BITT is dummy parameter, 0 or 1 ;save content AX to Stack mem ;bit 0 of AL = 0 or 1 ; Out Data bit via PA0

; Set Clock bit

OUT 0E0h,AL

; Send Clock via PA1

NOP

; delay 2 cycles for clock pulse’s fat enough

NOP

; No Operation

AND AL, 11111101b ; Reset Clock bit

OUT 0E0h,AL

POP AX

ShiftBIT

ENDM

; = = = = = = = = = = = = = = = = = = =

BCD_7SEG

PROC Near

; Cnvrt 6 digit BCD in BCD_Buf to 7S

MOV CX,6

; Counter = 6

B1:

MOV SI,offset @7SegBuf MOV BP,offset BCD_Buf MOV BX,offset Table7Seg

; LEA BX, Table7Seg

MOV AL,[BP] ; read BCD to AL

XLAT

; Convert BCD to 7 segment by TRANSLATE

MOV [SI],AL INC BP INC SI LOOP B1 RET BCD_ 7SEG ENDP

; = = = = = = = = = = = = = = = = = = =

SHIFT6BYTE PROC Near

; Shift a byte from @7SegBuf to

;HC595s

S4:

MOV BX,offset @7SegBuf MOV DL,6 MOV CX,8

; Counter of 6 digits ; counter of 8 bit/digit

 

MOV AL, [BX]

S3:

SHL AL,1

; Shift Left AL via Carry Flag, MSB is first

JNC S1

; jump if this bit is zero, If

..

Then

Else

strctr

ShiftBIT 1

; a MACRO, shifting a bit 1

JMP S2

; Jumping over shift BIT 0 to continue

 

S1:

ShiftBIT 0

:Macro shift a bit

S2:

LOOP S3

; CX==CX-1 if CX <>0 then goto S2

 

INC BX

; Next bit

DEC DL

; Have 6 digits shifted?

 

JNE S4

; If not equ zero, goto S4

RET

;

SHIFT6BYTE

ENDP

 

END