Experiment 3 transfer instruction jump principle and its simple application programming
experimental result
task1
assume cs:code, ds:data data segment x db 1, 9, 3 len1 equ $ - x ; symbolic constants , $Refers to the offset address of the next data item. In this example, it is 3 y dw 1, 9, 3 len2 equ $ - y ; symbolic constants , $Refers to the offset address of the next data item. In this example, it is 9 data ends code segment start: mov ax, data mov ds, ax mov si, offset x ; Take symbol x Corresponding offset address 0 -> si mov cx, len1 ; From symbol x Number of consecutive byte data items at the beginning -> cx mov ah, 2 s1:mov dl, [si] or dl, 30h int 21h mov dl, ' ' int 21h ; Output space inc si loop s1 mov ah, 2 mov dl, 0ah int 21h ; Line feed mov si, offset y ; Take symbol y Corresponding offset address 3 -> si mov cx, len2/2 ; From symbol y Number of consecutive word data items started -> cx mov ah, 2 s2:mov dx, [si] or dl, 30h int 21h mov dl, ' ' int 21h ; Output space add si, 2 loop s2 mov ah, 4ch int 21h code ends end start
As shown in the figure, the assembly language code corresponding to the loop instruction is E2F2, E2 represents loop, F2 represents offset, and its binary form is 11110010
Convert the complement to the original code as 10001110 = - 14
As shown in the figure, the assembly language code corresponding to the loop instruction is E2F0, E2 represents loop, F2 represents offset, and its binary form is 11110000
Convert the complement to the original code as 10010000 = - 16 = - 10
The offset address is Ox(39-10)=Ox(29)
The length of the add instruction is different from that of the inc instruction, so the offset is different
task2
assume cs:code, ds:data data segment dw 200h, 0h, 230h, 0h data ends stack segment db 16 dup(0) stack ends code segment start: mov ax, data mov ds, ax mov word ptr ds:[0], offset s1 mov word ptr ds:[2], offset s2 mov ds:[4], cs mov ax, stack mov ss, ax mov sp, 16 call word ptr ds:[0] s1: pop ax call dword ptr ds:[2] s2: pop bx pop cx mov ah, 4ch int 21h code ends end start
assume cs:code, ds:data data segment x db 99, 72, 85, 63, 89, 97, 55 len equ $ - x data ends code segment start: mov ax,data mov ds,ax mov byte ptr ds:[len],10;Stored divisor mov cx,7 mov bx,0 s: mov al,ds:[bx] mov ah,0 inc bx call printNumber call printSpace loop s mov ah,4ch int 21h printNumber: div byte ptr ds:[len];ah Save the remainder; al Depositary mov dx,ax;dh Save the remainder; dl Depositary mov ah,2 or dl,30h;30h Corresponding to character 0 ascii code int 21h mov ah,2 mov dl,dh or dl,30h int 21h ret printSpace: mov dl,' ' mov ah,2 int 21h ret code ends end start
task4
assume cs:code,ds:data data segment str db 'try' len equ $ - str data ends code segment start: mov ax,data mov ds,ax mov bl,00000010B;colour mov bh,0;Line number mov cx,3;String length mov si,0;Character content offset address call printStr mov bl,00000100B mov bh,24 mov cx,3 mov si,0 call printStr mov ah,4ch int 21h printStr: mov ax,0b800h;Video memory address mov es,ax mov ax,0 mov al,bh mov dx,160;Calculate the video memory address where the line number is located mul dx mov di,ax s: mov al,ds:[si] mov es:[di],al;Display character inc si inc di mov es:[di],bl;set up yanse inc di loop s ret code ends end start
The result of 8-bit multiplication is placed in ax (the high bit of the result of 16 bit multiplication is placed in dx and the low bit is placed in AX), and mul 160 obtains the offset address of the corresponding line number in the video memory; the lower eight bits of the video memory address store characters and the upper eight bits store colors;
task5
assume cs:code, ds:data data segment stu_no db '201983290347' len = $ - stu_no len1 = (80-len)/2 data ends code segment start: mov ax,data mov ds,ax mov bl,00010000b call printColor mov si,0 mov bl,00010111b mov bh,24 call printStr mov ah,4ch int 21h printColor: mov ax,0b800h mov es,ax mov ax,0 mov al,25 mov dx,0 mov dx,80 mul dx mov cx,ax mov al,' ' mov di,0 s: mov es:[di],al inc di mov es:[di],bl inc di loop s ret printStr: mov ax,0b800h mov es,ax mov ax,0 mov al,bh mov dx,160 mul dx mov di,ax mov al,'-' mov cx,len1 s1: mov es:[di],al inc di mov es:[di],bl inc di loop s1 mov cx,len s2: mov al,ds:[si] mov es:[di],al inc si inc di mov es:[di],bl inc di loop s2 mov al,'-' mov cx,len1 s3: mov es:[di],al inc di mov es:[di],bl inc di loop s3 ret code ends end start