当前位置:网站首页>Chapter V exercises (124, 678, 15, 19, 22) [microcomputer principles] [exercises]
Chapter V exercises (124, 678, 15, 19, 22) [microcomputer principles] [exercises]
2022-06-26 00:46:00 【Sun star moon cloud】
Preface
The following is derived from the principle of Microcomputer ( The Fourth Edition ) Edited by Wang Zhongmin
For learning and communication only
Please read the article statement , By default, I agree with this statement
exercises
1
1 Draw a diagram to illustrate the storage space allocated by the following statements and the initialized data values .
(1) BYTE_VAR DB 'BYTE’, 12,-12H,3 DUP(0,7,2DUP(1,2),7)
(2) WORD_ VAR DW 5 DUP(0,1,2),7,-5, ‘BY’, ‘TE’, 256H
1.asm
data segment
BYTE_VAR DB 'BYTE',12,-12H,3 DUP(0,7,2 DUP(1,2),7)
org 40h
WORD_VAR DW 5 DUP(0,1,2),7,-5,'BY','TE',256H
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov ah,4ch
int 21h
code ends
end start
2
Suppose the data in the program is defined as follows :
PARTNO DW ?
PNAME DB 16 DUP(?)
COUNT DD ?
PLENTH EQU $-PARTNO;16h=22
be PLENTH What is the value of ? What does it mean ?
PLENTH The value of is 0016h=22, It indicates the number of currently allocated cell space ;
PARTNO 2
PNAME 16
COUNT 4

2.asm
data segment
PARTNO DW ?
PNAME DB 16 DUP(?)
COUNT DD ?
PLENTH EQU $-PARTNO
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov ax,PLENTH
mov ah,4ch
int 21h
code ends
end start
4
4. Suppose the data in the program is defined as follows
LNAME DB 30 DUP(?)
ADDRESS DB 30 DUP(?)
CITY DB 15 DUP(?)
CODE_LIST DB 1,7,8,3,2
(1) Use one MOV Instructions will be LNAME The offset address of is put into BX.
(2) Use an instruction to put CODE_LIST The contents of the first two bytes of are put into SI.
(3) Write a pseudo instruction definer to make CODB_LENGHT The value is equal to the CODE_LIST The actual length of the field .
4.asm
data segment
LNAME DB 30 DUP(?)
ADDRESS DB 30 DUP(?)
CITY DB 15 DUP(?)
CODE_LIST DB 1,7,8,3,2
;(3) Write a pseudo instruction definer to make CODB_LENGHT The value is equal to the CODE_LIST The actual length of the field .
CODB_LENGHT EQU $-CODE_LIST
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
; verification (3)
mov ax,CODB_LENGHT
;(1) Use one MOV Instructions will be LNAME The offset address of is put into BX.
mov bx,offset LNAME
;(2) Use an instruction to put CODE_LIST The contents of the first two bytes of are put into SI.
mov si,WORD PTR CODE_LIST
mov ah,4ch
int 21h
code ends
end start


6
6. For the following data definitions , Articles MOV After the instruction is executed separately , What is the content of the register ?
FLDB DB?
TABLEA DW 20DUP(?)
TABLEB DB ‘ABCD'
(1) MOV AX, TYPE FLDB ;(AX)=1
(2) MOV AX, TYPE TABLEA ;(AX)=2
(3) MOV CX, LENGTH TABLEA ;(CX)=20
(4) MOV DX, SIZE TABLEA ;(DX)=40
(5) MOV CX, LENGTH TABLEB ;(CX)=1; Unused DUP
6.asm
data segment
FLDB DB ?
TABLEA DW 20 DUP(?)
TABLEB DB 'ABCD'
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
MOV AX, TYPE FLDB ;(AX)=1
MOV AX, TYPE TABLEA ;(AX)=2
MOV CX, LENGTH TABLEA ;(CX)=20
MOV DX, SIZE TABLEA ;(DX)=40
MOV CX, LENGTH TABLEB ;(CX)=1; Unused DUP
mov ah,4ch
int 21h
code ends
end start
7
7. Try to explain which of the following instructions need to be added PTR Pseudo instruction definer
BVAL DB 10H,20H
WVAL DW 1000H
(1) MOV AL, BVAL
(2) MOV DL, [BX]
(3) SUB [BX],2
(4) MOV CL,WVAL
7.asm
data segment
BVAL DB 10H,20H
WVAL DW 1000H
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
MOV AL,BVAL
MOV DL,[BX]
SUB [BX],BYTE PTR 2
MOV CL,BYTE PTR WVAL
mov ah,4ch
int 21h
code ends
end start


8
8. Write a macro definition BXCHG, Set the height of one byte 4 Bit and low 4 Bit exchange .
data segment
NUM1 DB 12H;-->21
NUM2 DB 34H;-->43
NUM3 DB 56H;-->65
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
BXCHG MACRO NUM
mov cl,4
rol NUM,cl; Cyclic shift to the left 4 position
ENDM
BXCHG NUM1
BXCHG NUM2
BXCHG NUM3
mov ah,4ch
int 21h
code ends
end start

15
15. Try to write an assembly language program , Request to receive a... From the keyboard 4 Hexadecimal number of bits , And display on the terminal
Show its binary equivalent .
Not 16 Hexadecimal characters press 0 Handle 
data segment
INF1 DB "Please input a hex mumber :$"
INF2 DB 0AH,0DH,"$"
INF3 DB " $"
org 60H
IBUF DB 7,0,6 DUP('$')
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
; Output INFO
PINF MACRO INF
MOV DX,OFFSET INF
MOV AH,09H
INT 21H
ENDM
; Take out each bit and output
QUWEI MACRO NUM
MOV CX,4
SHL NUM,CL; To shift four digits left to a significant number ,0f->f0
LOOP1:
SHL NUM,1
JC P1
JNC P0
P1:
PUSH DX;MOV DL,'1' Will change
MOV AH,2
MOV DL,'1'
int 21h
POP DX
JMP END1
P0:
PUSH DX
MOV AH,2
MOV DL,'0'
int 21h
POP DX
JMP END1
END1:
NOP
LOOP LOOP1
ENDM
; Output BUF
PBUF MACRO BUF
MOV CX,0
MOV CL,[BUF+1]
LEA BX, BUF+2
LOOP3:
PUSH CX;QUWEI DL; Will change CX
;MOV DL,[BX]
;ADD DL,30H
;MOV AH, 02H
;INT 21H
MOV DL,[BX]
QUWEI DL
INC BX
POP CX
PINF INF3; One bit per revolution 16 Base to 4 position 2 Base to a space
LOOP LOOP3
ENDM
; Input --》BUF
STORE MACRO BUF
MOV DX, OFFSET IBUF ; Type a hexadecimal number
MOV AH,0AH
INT 21H
ENDM
PINF INF1
CALL HTB
PINF INF2
PBUF IBUF
mov ah,4ch
int 21h
;DTB rewrite HTB
;MOV DX,10-->MOV DX,16
HTB PROC NEAR
STORE IBUF
MOV CL,IBUF+1; The number of decimal digits is sent to CX
MOV CH,0
MOV SI,OFFSET IBUF+2; Point to the first character of the input ( highest )
MOV AX,0 ; Start converting decimal numbers to binary numbers
AGAIN:
;MOV DX,10;((0x10+a4)x10+...)x10+a0
MOV DX,16;((0x16+a4)x16+...)x16+a0
MUL DX
;AND BYTE PTR [SI],0FH; The decimal system can be converted into numbers
;16 The base number needs to be changed
CMP BYTE PTR [SI],'0'
JB OTHER
CMP BYTE PTR [SI],'9'
JBE DIGIT
CMP BYTE PTR [SI],'A'
JB OTHER
CMP BYTE PTR [SI],'F'
JBE UPPER
CMP BYTE PTR [SI],'a'
JB OTHER
CMP BYTE PTR [SI],'f'
JBE LOWER
JMP PEND
LOWER:
; Lowercase letters a->10
SUB BYTE PTR [SI],'a'
ADD BYTE PTR [SI],10
JMP PEND; Note that the program should jump out after executing a branch
UPPER:
; Capital A->10
SUB BYTE PTR [SI],'A'
ADD BYTE PTR [SI],10
JMP PEND
DIGIT:
AND BYTE PTR [SI],0FH; The situation of numbers
JMP PEND
OTHER:
AND BYTE PTR [SI],0H; Input not 16 Hexadecimal characters press 0 Handle
JMP PEND
PEND:
ADD AL, [SI]
ADC AH,0
INC SI
LOOP AGAIN
RET
HTB ENDP
code ends
end start
19
19. Enter a series of characters from the keyboard ( End with carriage return ), And press letters 、 Count numbers and other characters by category , most
The counting results of these three categories are displayed .
19.asm
data segment
INF1 DB "Please input a string :$"
INF2 DB 0AH,0DH,"$"
INF3 DB " $"
org 40H
CNTN DB 0 ; Number of numbers
CNTC DB 0 ; Number of letters
CNTO DB 0 ; Other numbers
org 60H
IBUF DB 255,0,254 DUP('$')
OBUF DB 7,0,6 DUP('$')
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
; Output INFO
PINF MACRO INF
MOV DX,OFFSET INF
MOV AH,09H
INT 21H
ENDM
; Input --》BUF
STORE MACRO BUF
MOV DX, OFFSET IBUF ; Type a hexadecimal number
MOV AH,0AH
INT 21H
ENDM
; Output BUF
PBUF MACRO BUF
MOV CX,0
MOV CL,[BUF+1]
LEA BX, BUF+2
LOOP3:
MOV DL,[BX]
ADD DL,30H
MOV AH, 02H
INT 21H
INC BX
LOOP LOOP3
ENDM
; Statistics
CNT MACRO
STORE IBUF
MOV CL,IBUF+1; The number of decimal digits is sent to CX
MOV CH,0
MOV SI,OFFSET IBUF+2; Point to the first character of the input ( highest )
MOV AX,0 ; Start converting decimal numbers to binary numbers
AGAIN:
CMP BYTE PTR [SI],'0'
JB OTHER
CMP BYTE PTR [SI],'9'
JBE DIGIT
CMP BYTE PTR [SI],'A'
JB OTHER
CMP BYTE PTR [SI],'Z'
JBE UPPER
CMP BYTE PTR [SI],'a'
JB OTHER
CMP BYTE PTR [SI],'z'
JBE LOWER
CMP BYTE PTR [SI],'z'
JA OTHER
JMP PEND
LOWER:
INC CNTC
JMP PEND; Note that the program should jump out after executing a branch
UPPER:
INC CNTC
JMP PEND
DIGIT:
INC CNTN
JMP PEND
OTHER:
INC CNTO
JMP PEND
PEND:
ADD AL, [SI]
ADC AH,0
INC SI
LOOP AGAIN
ENDM
;AL->BCD; compressibility
HTBCD MACRO
mov ah,0
mov cl,4
push ax
shr al,cl
mov bl,16h
mul bl
pop bx
and bl,0fh
add al,bl
daa
ENDM
; Output BCD code ;AL compressibility
PBCD MACRO
mov ah,0
mov cl,4
push ax
shr al,cl
mov bh,al ;al High position
pop ax
and al,0fh ;al Low position
mov ah,bh ;al High position
push ax
mov dl,ah
add dl,30h
mov ah,2
int 21h
pop ax
push ax
mov dl,al
add dl,30h
mov ah,2
int 21h
pop ax
ENDM
PINF INF1
CNT
PINF INF2
mov ax,0
mov al,CNTN
HTBCD
PBCD
PINF INF3
mov al,CNTC
HTBCD
PBCD
PINF INF3
mov al,CNTO
HTBCD
PBCD
mov ah,4ch
int 21h
code ends
end start
22
22. Write two 4 Bit uncompressed BCD Sum of the numbers , The program that sends the and to the display .
22.asm
data segment
INF1 DB "RESULT:$"
INF2 DB 0AH,0DH,"$"
INF3 DB " $"
org 20H
STRING1 DW 0001H
STRING2 DW 0019H
D DB 0h ;0h
SUM DW 0H ;0020h
;STRING1 DW 0001H
;STRING2 DW 0099H
;D DB 0h ;0h
;SUM DW 0H ;0100h
;STRING1 DW 0001H
;STRING2 DW 9999H
;D DB 0h ;1h
;SUM DW 0H;0020h ;0000h
org 60H
IBUF DB 255,0,254 DUP('$')
OBUF DB 7,0,6 DUP('$')
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
; Output INFO
PINF MACRO INF
MOV DX,OFFSET INF
MOV AH,09H
INT 21H
ENDM
; Input --》BUF
STORE MACRO BUF
MOV DX, OFFSET IBUF ; Type a hexadecimal number
MOV AH,0AH
INT 21H
ENDM
; Take out bx:BCD Count each bit and output
QUWEI MACRO
PUSH BX
MOV CX,12
SHR BX,CL
MOV DL,BL
ADD DL,30H
MOV AH,02H
int 21h
POP BX
PUSH BX
MOV CX,8
SHR BX,CL
AND BX,0FH
MOV DL,BL
ADD DL,30H
MOV AH,02H
int 21h
POP BX
PUSH BX
MOV CX,4
SHR BX,CL
AND BX,0FH
MOV DL,BL
ADD DL,30H
MOV AH,02H
int 21h
POP BX
PUSH BX
AND BX,0FH
MOV DL,BL
ADD DL,30H
MOV AH,02H
int 21h
POP BX
ENDM
PINF INF1
PINF INF2
; Calculation
;ax,bx On behalf of the digital
;cl, Express al+bl Carry of
;ch, Express ah+bh Carry of
mov ax,STRING1
mov bx,STRING2
mov cx,0
push ax
add al,bl
daa
adc cl,0
mov dx,ax
pop ax
; The carry of the lower order is required
add ah,cl
add ah,bh
mov al,ah
daa
adc ch,0
mov dh,al
; The result is ch ,dx
mov D,ch
mov SUM,dx
; Show
mov dl,D
add dl,30H
mov ah,2
int 21h
mov bx,sum
QUWEI
mov ah,4ch
int 21h
code ends
end start



simplify QUWEI
data segment
INF1 DB "RESULT:$"
INF2 DB 0AH,0DH,"$"
INF3 DB " $"
org 20H
STRING1 DW 0001H
STRING2 DW 0019H
D DB 0h ;0h
SUM DW 0H ;0020h
;STRING1 DW 0001H
;STRING2 DW 0099H
;D DB 0h ;0h
;SUM DW 0H ;0100h
;STRING1 DW 0001H
;STRING2 DW 9999H
;D DB 0h ;1h
;SUM DW 0H;0020h ;0000h
org 60H
IBUF DB 255,0,254 DUP('$')
OBUF DB 7,0,6 DUP('$')
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
; Output INFO
PINF MACRO INF
MOV DX,OFFSET INF
MOV AH,09H
INT 21H
ENDM
; Input --》BUF
STORE MACRO BUF
MOV DX, OFFSET IBUF ; Type a hexadecimal number
MOV AH,0AH
INT 21H
ENDM
PDL MACRO
ADD DL,30H
MOV AH,02H
int 21h
ENDM
; Take out bx:BCD Count each bit and output
QUWEI MACRO
LOCAL NEXT
MOV CX,12
;CX=12,8,4
NEXT:
PUSH BX
SHR BX,CL
MOV DL,BL
PDL
POP BX
SUB CX,4
JNZ NEXT
;CX=0
AND BX,0FH
MOV DL,BL
PDL
ENDM
PINF INF1
PINF INF2
; Calculation
;ax,bx On behalf of the digital
;cl, Express al+bl Carry of
;ch, Express ah+bh Carry of
mov ax,STRING1
mov bx,STRING2
mov cx,0
push ax
add al,bl
daa
adc cl,0
mov dx,ax
pop ax
; The carry of the lower order is required
add ah,cl
add ah,bh
mov al,ah
daa
adc ch,0
mov dh,al
; The result is ch ,dx
mov D,ch
mov SUM,dx
; Show
mov dl,D
PDL
mov bx,sum
QUWEI
mov ah,4ch
int 21h
code ends
end start
Last
Please read the article statement , By default, I agree with this statement
Reward channels 
边栏推荐
- Web学习之TypeScript
- Flink报错:Error: A JNI error has occurred, please check your installation and try again
- Openresty chapter 01 introduction and installation configuration
- Idea set the template of mapper mapping file
- 【系统架构】-什么是MDA架构、ADL、DSSA
- Anti shake and throttling
- C IO stream (II) extension class_ Packer
- 【OEM专场活动】清“芯”夏日,有奖征文
- js数组中修改元素的方法
- SMT Mounter workflow
猜你喜欢

Idea kotlin version upgrade

删库跑路、“投毒”、改协议,开源有哪几大红线千万不能踩?

EBS r12.2.0 to r12.2.6

渲云携手英特尔,共创云渲染“芯”时代
![[image detection] vascular tracking and diameter estimation based on Gaussian process and Radon transform with matlab code](/img/1d/511dceb9decd73976d577af991afc9.png)
[image detection] vascular tracking and diameter estimation based on Gaussian process and Radon transform with matlab code

Example: use C # Net to teach you how to develop wechat official account (21) -- using wechat to pay online collection: H5 method

1-10vmware builds customized network architecture

学习识别对话式问答中的后续问题

AD20(Altium Designer) PCB 高亮网络

Atlas200dk brush machine
随机推荐
Mysql5.7.31 user defined installation details
11.1.1 overview of Flink_ Flink overview
Ad20 (Altium designer) PCB highlight network
基于OpenVINOTM开发套件“无缝”部署PaddleNLP模型
Reentrant functions must be used within signal processing functions
从进程的角度来解释 输入URL后浏览器会发生什么?
Should group by be used whenever aggregate functions are used in SQL?
Causes and solutions to the phenomenon of PCBA monument in SMT patch processing
Redux workflow + complete code of small examples
Why do we need to make panels and edges in PCB production
Use js to obtain the last quarter based on the current quarter
防抖和节流
CXF
使用VS2022編譯Telegram桌面端(tdesktop)
Solution to component stele in SMT chip processing
WordPress
Servlet response download file
Qt优秀开源项目之九:qTox
论文中英文大小写、数字与标点的正确撰写方式
Analyze the five root causes of product development failure