201983290125 assembly language experiment 2

1. Task 1

 

1-1

Assemble and connect task1_1.asm

 

Use the g command to break the point, stop the program until line 17, and check the value of the register

 

 (1)ds=076A;

          ss=076B;

          cs=076C;

(2)ds=X-0002;

         ss=X-0001;

 

1-2

 

 (1)ds=076A

          ss=076B;

          cs=076C;

(2)ds=X-0002;

         ss=X-0001;

 

1-3

 

(1)ds=076A

          ss=076C;

          cs=076E;

(2)ds=X-0004;

         ss=X-0002;

 

1-4

 

(1)ds=076C;

          ss=076E;

          cs=076A;

(2)ds=X+0002;

         ss=X+0004;

 

1-5

(1) If the data in the segment accounts for n bytes, after the program is loaded, the space actually occupied by the segment is (n+15)/16, that is, the N/16 is rounded up, because the segment size is an integer multiple of 16 bytes, and the dissatisfied part should also be supplemented with 16 bytes.

(2)

Only 1-4 can be executed for the following reasons:

The start label indicates the beginning of the program segment, and end start indicates the end of the program segment. Start and end start must appear in pairs. If end start does not exist, the start label is ignored and treated as the default. When the beginning of the program is the program entry, it can be defaulted.

Only 1-4 starts with a code segment, so only 1-4 can be executed.

 

2. Task 2

  The code is as follows:

assume cs:code
code segment
    
    mov ax,0b800h
    mov ds,ax
    mov bx,0f00h
    mov cx,80
p:
    mov ds:[bx],0403h
    inc bx
    inc bx
    loop p

    mov ah,4ch
    int 21h
code ends

  The results are as follows:

 

3. Task 3

The code is as follows

assume cs:code
data1 segment
    db 50, 48, 50, 50, 0, 48, 49, 0, 48, 49 ; ten numbers
data1 ends

data2 segment
    db 0, 0, 0, 0, 47, 0, 0, 47, 0, 0       ; ten numbers
data2 ends

data3 segment
    db 16 dup(0)
data3 ends

code segment
start:
mov ax,data1
mov ds,ax
mov ax,data2
mov es,ax
mov ax,data3
mov ss,ax
mov bx,0
mov cx,10
s:
mov ax,0
add ax,ds:[bx]
add ax,es:[bx]
mov ss:[bx],ax
inc bx
loop s

mov ax,4c00h
int 21h

code ends
end start

Value when code snippet is not entered

 

data1 is 10 units starting from 076a: 0000. Data2 and data3 start from 076b and 076c respectively. It can be seen that all 076c are 0 at this time

After operation, the 076c results are as follows

 

  Becomes data1+data2

 

4. Task 4

The code is as follows:

assume cs:code

data1 segment
    dw 2, 0, 4, 9, 2, 0, 1, 9
data1 ends 

data2 segment
    dw 8 dup(?)
data2 ends

code segment
start:
    mov ax,data1
    mov ds,ax
    mov ax,data2
    mov ss,ax
    mov cx,8
    mov sp,16
    mov bx,0
s:
    mov ax,[bx]
    push ax
    inc bx
    inc bx
    loop s
    
    mov ah, 4ch
    int 21h
code ends
end start

  Before entering the code snippet:

 

After the code snippet runs

 

 

5. Task 5

Run program

 

  Execute between lines 25 and 27

 

  line 19 action

Sum the memory unit value in data1 with 0dfh, that is, the hexadecimal number df, and df is converted into binary to 11011111. The sum operation turns the original number of bit 6 into 0,

The upper case letters ascii range from 01000001 to 01011010, and the lower case letters are 0110001-01111010. Therefore, change the 1 in the sixth digit of the lower case letter to 0 to convert lower case to upper case,

The original 0 of the capital letter remains unchanged, so all letters in line 19 become capital.

 

Change to db 5 dup(2)

The results are as follows:

 

  A character occupies a word, that is, 2 bytes. Does the low byte represent ascii, the high byte represents character parameters, the high 4-bit background color, and the color of the fourth character itself.

 

6. Task 6

assume cs:code, ds:data

data segment
    db 'Pink Floyd      '
    db 'JOAN Baez       '
    db 'NEIL Young      '
    db 'Joan Lennon     '
data ends

code segment
start:
   mov ax,data
   mov ds,ax
   mov cx,4
   mov bx,0
s:
   mov dx,cx
   mov cx,4
   mov si,0
p:
   mov al,ds:[bx+si]
   or al,00100000B
   mov ds:[bx+si],al
   inc si
   loop p
add bx,16
mov cx,dx
loop s
   mov ah, 4ch
   int 21h
code ends
end start

 

 

 

 

7. Task 7

 

assume cs:code, ds:data, es:table

data segment
    db '1975', '1976', '1977', '1978', '1979' 
    dw  16, 22, 382, 1356, 2390
    dw  3, 7, 9, 13, 28 
data ends

table segment
    db 5 dup( 16 dup(' ') )  ;
table ends

code segment
start:
    mov ax,data
    mov ds,ax
    mov ax,table
    mov es,ax
    mov bx,0
    mov si,0
    mov cx,5
p:
    mov ax,ds:[bx]
    mov es:[si],ax
    mov ax,ds:[bx+2]
    mov es:[si+2],ax
    add bx,4
    add si,16
    loop p
    mov bx,20
    mov cx,5
    mov si,5
s:
    mov ax,0
    mov es:[si+2],ax
    mov ax,ds:[bx]
    mov es:[si],ax
    add bx,2
    add si,16
    loop s
    mov bx,30
    mov cx,5
    mov si,10
q:
    mov ax,ds:[bx]
    mov es:[si],ax
    add bx,2
    add si,16
    loop q
    mov cx,5
    mov si,0
r:
    mov ax,es:[si+5]
    mov dx,es:[si+7]
    div word ptr es:[si+10]
    mov es:[si+13],ax
    add si,16
    loop r



    mov ah, 4ch
    int 21h
code ends
end start
assume cs:code, ds:data, es:table

data segment
    db '1975', '1976', '1977', '1978', '1979' 
    dw  16, 22, 382, 1356, 2390
    dw  3, 7, 9, 13, 28 
data ends

table segment
    db 5 dup( 16 dup(' ') )  ;
table ends

code segment
start:
    mov ax,data
    mov ds,ax
    mov ax,table
    mov es,ax
    mov bx,0
    mov si,0
    mov cx,5
p:
    mov ax,ds:[bx]
    mov es:[si],ax
    mov ax,ds:[bx+2]
    mov es:[si+2],ax
    add bx,4
    add si,16
    loop p
    mov bx,20
    mov cx,5
    mov si,5
s:
    mov ax,0
    mov es:[si+2],ax
    mov ax,ds:[bx]
    mov es:[si],ax
    add bx,2
    add si,16
    loop s
    mov bx,30
    mov cx,5
    mov si,10
q:
    mov ax,ds:[bx]
    mov es:[si],ax
    add bx,2
    add si,16
    loop q
    mov cx,5
    mov si,0
r:
    mov ax,es:[si+5]
    mov dx,es:[si+7]
    div word ptr es:[si+10]
    mov es:[si+13],ax
    add si,16
    loop r



    mov ah, 4ch
    int 21h
code ends
end start

 

  Before and after operation:

 

 

 

 

  Experiment summary:

1. Master the usage of loop through this experiment.

2. Understand the method of changing the case of letters through and, or operation

3. Understand the storage mode of characters in memory.

 

 

 

 

 

 

 

 

 

 

 

 

 

         

 

Posted by fatnjazzy on Sun, 07 Nov 2021 19:41:10 -0800