Professional Documents
Culture Documents
CHAPTER 8 PC ASSEMBLERs Microsoft Macro Assembler for PC Turbo Assemble - Borland DOS/BIOS Functions
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
SEGMENTENDS 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
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;
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.
;= = = = = = = = = DECLARING = = = = = = = = = = = = = = = = = = = = = .MODEL SMALL ; Declaring model of program: ; tiny/small/medium/large/huge/flat .STACK 64 ; Stack Mem .DATA ; !!! there is a dots front of logical segment Table7Seg DB 3FH, 06H, 5BH, 4FH, 66H, 6DH, 7DH, 07H, 7FH, 6FH ; ; Table contains 10 bytes of 7 seg codes, 0 - 9 @7SegBuf DB 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, DOSs 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 ; Shifting to HC595 IN AL,0E0h ; Displaying OR AL,00000100b ; SET LATCH PULSE OUT 0E0h,AL ; LEDs are turned on after NOP NOP ; Delay 2 machine cycles for Latch pulse is wide enough AND AL,11111011b ; RESET PULSE OUT 0E0h, AL ;
;==================================== MOV AH, 0 Int 16h ; Wait for key pressed to terminate MOV AH,4CH ; Terminating an .exe file a DOS function INT 21H Chinh ENDP ; = = = = = = PROCEDURES AND MACROES ARE DECLARED HERE Init_PPI MACRO PUSH AX MOV AL,10000010b ; PA, PB, PC mode 0, PA, PC out, PB in OUT 0E3h,AL ; Sending to PPI Control Register MOV AL,00001000b ; 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 ; Read PA AND AL,11110111b ; Clear pins = 0 OUT 0E0h,AL NOP ; Delay for 2 Machine cycles NOP OR AL,00001000b ; Un-clear HC595 OUT 0E0h,AL ; Send to PA Clear_595 ENDM ;================== ShiftBIT MACRO BITT ; BITT is dummy parameter, 0 or 1 PUSH AX ;save content AX to Stack mem MOV AL,BITT ;bit 0 of AL = 0 or 1 OUT 0E0h,AL ; Out Data bit via PA0 NOP OR AL, 00000010b ; Set Clock bit
OUT 0E0h,AL ; Send Clock via PA1 NOP ; delay 2 cycles for clock pulses 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 MOV SI,offset @7SegBuf MOV BP,offset BCD_Buf B1: 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 MOV BX,offset @7SegBuf MOV DL,6 ; Counter of 6 digits S4: MOV CX,8 ; counter of 8 bit/digit
10
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
11