Microcontroller assembly language programming (online for answers)
<< < Question 1>>
Experiment purpose: preliminary understanding of the working principle of the microcontroller I / O port, to further master the assembly instructions of the 51 microcontroller.
Experiment content: programming the microcontroller I/O port with assembly instructions to control the 8 light-emitting diodes of the flow of water on and off.
Detailed program features:
Do a single light left to right, eight light-emitting diodes L0-L7 were connected to the microcontroller’s P1.0-P1.7 interface,
Output “0”, light-emitting When “0” is output, the light-emitting diode lights up, and at the beginning, P1.0→P1.1→P1.2→P1.3→…→P1.7→P1.6→…→P1.0 lights up, and the cycle is repeated.
ORG0000H
LJMPSTART
ORG0030H
MOVR2,#8;number of times of left shift
MOVA,#0FEH;Initial value of A, i.e., L0 of P1.0 is lit
SETBC
LOOP:MOVP1, A
LCALLDELAY
RLCA;Left shift running lamp (left shift with rounding), i.e., the highlight moves to the high bit of P1 port
DJNZR2,LOOP
MOVR2,#8;Right shift count
LOOP1:RRCA;Right shift running lamp
MOVP1, A
LCALLDELAY
DJNZR2,LOOP1
LJMPSTART
DELAY:MOVR5,#10;delay subroutine,change the value of R5,R6,R7,you can change the time of the delay,so as to change the speed of the moving lamp
D1. MOVR6,#20
D2:MOVR7,#248
DJNZR7,$
DJNZR6,D2
DJNZR5,D1
RET
END
<< < Question 2>>
Experiment purpose: to master the principle of microcontroller lookup table, master MOVDPTR, # DATA16 instruction, MOVCA,@A + DPTR use
Experiment content: the use of MOVCA,@A + DPTR instruction, control 8 light-emitting diode running water bright and dark.
Detailed function of the program:
The use of the method of taking the table, so that the port P1 to do a single light change: 2 times to the left, 2 times to the right, blinking 2 times (the time of the delay of 0.2 seconds).
When programming with the table, the following instructions are to be used
(1). Use the instruction MOVDPTR, #DATA16 to make the data pointer register point to the beginning of the table.
(2). The instruction MOVCA,@A + DPTR is utilized to make the program counter PC point to the data to be taken out of the table based on the value of the accumulator plus the value of DPTR.
*Thus, as long as the control code is built into a table, and the MOVCA,@A + DPTR is used to do the operation of fetching the code,
*it can be convenient to deal with some complex control actions.
*/
ORG0000H
LJMPSTART
ORG0100H
START:
MOVDPTR,#TABLE;Fetch the address of DPTR, which is the starting address of the table
LOOP:
LOOP:
CLRA;[
MOVCA,@A + DPTR,@A + DPTR,@A + DPTR].
CLRA;Zero A
MOVCA,@A+DPTR;check the table
CJNEA,#01H,LOOP1;determine whether to the end of the table, when A is equal to 01 when the program is executed down, otherwise jump to LOOP1
LJMPSTART;jump to the beginning of the program to execute the cycle
LOOP1:
MOVP0,A;send the table data to P0
LCALLDELAY;delay
INCDPTR;add one to DPTR,i.e.point DPTR to the next table unit
LJMPLOOP
DELAY:MOVR5,#10;delay subroutine, change the value of R5, R6, R7, you can change the delay time, so as to change the speed of the moving lights
D1:MOVR6,#20
D2:MOVR7,#248
DJNZR7,$
DJNZR6,D2
DJNZR5,D1
RET
;The following is the pattern table of the running lights, each data corresponds to the state of the LED under one moment
;The data of TABLE will be finally arranged by the compiler into the FLASH program storage area of the microcontroller, which can only be read but not modified when the CPU is running.
TABLE:
DB0FEH,0FDH,0FBH,0F7H
DB0EFH,0DFH,0BFH,07FH
DB0FEH,0FDH,0FBH,0F7H
DB0EFH,0DFH,0BFH,07FH
DB07FH,0FH,07FH
< p>DB07FH,0BFH,0DFH,0EFH
DB0F7H,0FBH,0FDH,0FEH
DB07FH,0BFH,0DFH,0EFH
DB0F7H,0FBH,0FDH,0FEH
DB00H,0FFH,00H, 0FFH
DB01H
END
<< < Question 3>>
No more writing,,I’m tired!
Answers to Assembly Language Programming review questions for help, analysis questions! High marks, thanks!
41Answers are as follows:
SI is the source address register, DI is the destination address register, that is, the source address register [SI] to start the 64H bytes of the content, copied to the beginning of the address of [DI] space to go.CX is the counter, that is, to copy the content of the 64H bytes, MOVSB is the MOV to B as a unit!
42 Answers:
DATASEGMENT
ADW0
BDW0
CDW15H,5H,50H
DATAENDS
CODESEGMENT
.
.
MOVBX,OFFSETC
MOVAX,[BX]; after this step, AX = [BX] = 15H
MOVB,AX; B = 15H
MOVAX,2[BX]; 2[BX] means [BX+2], so AX = 05H
ADDAX,. B; 15H+05H=1AH
MOVA,AX; finally 1AH
VI. Program to fill in the blanks
First blank 0FH
Second blank 4AH.
The basic idea of this question is to shift the BX cycle right by four bits, take BL, assign it to AL, with the upper 0FH,clear the high four bits to zero, get the low four bits, and then add 30H to judge whether it is more than A, because the ASCLL of A is not consecutive with the ASCLL code of 0-9. According to the judgment result and then add 07H,that’s it.
I was originally an assembly section representative! Haha
Assembly language programming topics, waiting for answers online!!!! Urgent!
DATASEGMENT
ADB148;Write here: 0~255
BDB28;Write here: 0~255
DATAENDS
CODESEGMENT
ASSUMECS:CODE,DS:DATA<
START:
MOVAX,DATA
MOVDS,AX
MOVAL,A;fetch A
MOVAH,0
MOVBL,B;fetch B
MOVBH,0
ADDAX,BX;sum
SHRAX,1;divide by 2
DISP:;display in hex
MOVAH,0
MOVBL,16
DIVBL
PUSHAX
CMPAL,10
JBA30
ADDAL, 7
A30:
ADDAL,30H
MOVDL,AL
MOVAH,2
INT21H
POPAX
CMPAH,10
JBA302
ADDAH,7
A302:
ADDAH,30H
MOVDL,AH
MOVAH,2
INT21H
MOVDL,’H’
MOVAH,2
INT21H
MOVAH,4CH
INT21H
CODEENDS
ENDSTART
After the program is run, it will display the average value 58H in hexadecimal.