# Assembly Language Wang Shuang Experiment 100 Questions Answers

### Assembly Language 4th Edition Wang Shuang Reference Answers

I am also a first time learner, so please correct me if there are any mistakes!

(1) 1 CPU has an addressing capacity of 8KB, so the width of its address bus is 13 bits.

(2) 1KB of memory has 1024 memory cells, which are numbered from 0 to 1023.

(3) 1KB of memory can store 8192 bits, 1024 Bytes.

(4) 1GB is 1073741824 (2 ^30) Byte, 1MB is 1048576 (2^20) Byte, and 1KB is 1024 (2^10) Byte.

(5) The address bus widths of 8080, 8088, 80296, and 80386 are 16, 20, 24, and 32 bytes, respectively, and their addressing capabilities are. 64 (KB), 1 (MB), 16 (MB), 4 (GB).

(6) The data bus widths of 8080, 8088, 8086, 80286, and 80386 are 8, 8, 16, 16, and 32 respectively. Then the data they can transmit at a time is:1(B), 1(B), 2(B), 2(B), 4(B).

(7) To read 1024 bytes of data from memory, the 8086 has to be read at least 512 times and the 80386 at least 256 times.

(8) In memory, data and programs are stored in binary form.

Solution:

(1) 1KB=1024B, 8KB=1024B*8=2^N, N=13.

(2) The capacity of the memory is calculated in terms of bytes as the smallest unit, 1KB=1024B.

(3) ) 8Bit=1Byte, 1024Byte=1KB (1KB=1024B=1024B*8Bit).

(4) 1GB=1073741824B (i.e. 2^30) 1MB=1048576B (i.e. 2^20) 1KB=1024B (i.e. 2^10).

(5) A CPU with N address lines can be said to have an address bus with a width of N. Such a CPU can look for up to 2 to the Nth power of a memory cell. (One memory cell = 1Byte).

(6) The 8 data buses can transmit 8 bits of binary data (i.e., one byte) at a time.

(7) The 8086 has a data bus width of 16 (i.e., 2B of data transferred at a time) 1024B/2B = 512, and similarly 1024B/4B = 256.

(8) There is no difference between instructions and data in memory, they are both binary messages.

[2020.7.20]

(1) Write the value in the relevant register after execution of each assembly instruction.

movax,62627 AX=F4A3H

movah,31H AX=31A3H

moval,23H AX=3123H

< p>

movbx,826CH BX=826CH

movcx,ax CX=6246H

movax,bx AX=826CH

< p>moval,bh AX=0482H

movah,bl AX=6C82H

movax,cx AX=6246H

(2) Calculate the quadratic of 2

movax,2AX=2

[2020.7.20]

(1) Given a segment address of 0001H, addressed only by changing the offset address, the CPU’s addressing range is from 0010H to 1000FH.

Solution process:

EA varies from 0h to ffffh

< p>Now SA=0001h,then the addressing range is

(0001h*16+0h)~(0001h*16+ffffh)

=0010h~1000fh

(2)There is a data stored in the memory in cell 20000H,now given the segment address SA. If you want to find this cell with offset address. The conditions that SA should meet are: minimum 1001H, maximum 2000H.

When the segment address is given as 1001H or less and 2000H or more, the CPU will not be able to find the 20000H cell no matter how the offset address is changed.

Solution:

20000h=SA*16+EA

SA=(20000h-EA)/16=2000h-EA/16

EA takes the maximum value. p>EA take maximum value, SA=2000h-ffffh/16=1001h, SA is the minimum value

EA take minimum value, SA=2000h-0h/16=2000h, SA is the maximum value

The fffh/16=fffh here is calculated by the WIN calculator

Win calculator is the best way to calculate ffffh.

By displacement it should be fff.fh, here the f after the decimal point should be omitted

In division alone, there should be a quotient and remainder, but this question asks for the largest and smallest address, so the remainder is ignored

If you use the algorithm based on the displacement (segment address * 16 = 16), the remainder is ignored. If the algorithm is based on the shift algorithm (segment address *16 = 16), the decimal point should not be omitted

We can think about it the other way around, if SA is 1000h, then the decimal point should be omitted

SA=1000h, EA takes the maximum fffffh, and the physical address is 1ffffh, which would make it impossible to find the 20000H cell

This question should not be viewed as a purely computational question

[2020.7.20]

How many times does the cpu modify the IP after the following 3 instructions are executed and when are they all? What is the value in the IP at the end?

movax,bx

subax,ax

jmpax

Answer: it modifies it four times

ax

Fourth time: executing jmp

ax modifies the IP

The last value in the IP is 0000H because the The last value in ax is 0000H, so the value in IP is also 0000H

[2020.7.20]

### Assembly Language Lab 9 Kneeling for a detailed answer. I saw the answer on the internet but just can’t understand it! Thanks

;============================================================================================

;

;Wang Shuang assembly experiment 9 according to the material Programming

;Requirement: program the string ‘welcometomasm!’ in the middle of the screen in green, red on green, and blue on white.

;In 80*25 color character mode, the display can show 25 lines, 80 characters per line, and each character can have 256 attributes

;02H means green on black background

;00100100B means red on green background

;01110001B means blue on white background

;

;============================================================================================

assume cs:codesg,ds:datasg,ss. stacksg

datasgsegment

db ‘welcometomasm!’,0

datasgends

stacksgsegment

stacksgends

codesgsegment

start: mov ax,datasg

mov ds,ax

mov ax,0b800h

mov es,ax ;es is initialized to the video buffer segment address

;First step, work out where the middle of the screen will be

;The information given in the book is that a screen displays a total of 25 lines with 80 characters (160 bytes) per line

;Even bytes put the characters and odd bytes put the character attributes

;The length of the string to be displayed is 16 bytes, which is counted as 16 characters

mov ax,12 ;Line 13

mov bx,160

;The first step is to calculate the position in the middle of the screen

mul bl ;The first step is to calculate the position in the middle of the screen. p>

mul bl ;figure out how many bytes are in the first 12 lines, the result is in ax

add ax,64 ;the reason for adding 64 bytes is because (160-16*2)/2=64 bytes

;this ensures that the string is exactly in the center

mov di,ax ;put the result into the destination address register, with the es to point to the destination in the video buffer

mov si,0 ;initialize the source address register to point to the source string in the data segment

call ShowString ;call the subroutine that displays the string

mov ax,4c00h

int 21h

ShowString:

mov cx,7

;Show green welcome

loop1:

mov al,[si]

mov es:[di],al

mov byteptres:[di+1],02h

inc si

mov es:[di],al

mov byteptres:[di+1],02h

< p> inc si

inc di

inc di

loop loop1

;Show space after welcome

mov al,[si]

mov es:[di],al

inc si

inc di<

inc di

mov cx,2

;show red to on green

loop2:

mov al,[si]

mov es:[di],al

mov byteptres:[di],00100100B

inc si

inc di

inc di

loop loop2

;show space after to

mov al,[si]

mov es:[di],al

inc si

inc di

inc si

inc di

inc si

inc di

<

inc di

mov cx,4

;show blue masm on white background

loop3:

mov al,[si]

mov es:[di],al

mov byteptres:[di+1],01110001B

inc si

inc di

inc di

loop loop3

;Show last!

mov al,[si]

mov es:[di],al

ret

codesgends

endstart

;The result is still only visible in cmd full screen mode!!!!

### Assembly language Wang Shuang topic for the answer

POPAX; that the current top of the stack to point to the content of the first to send AX, according to the previous instruction to know at this time SS = 2000H, SP = 0010H, that is to say, it is to put the (SS:SP) – > (AX), the physical address is 20010H, and then SP + 2 –>SP,SP becomes 0012H.

POPBX;(SS:SP)–>(BX),physical address is 20012H,then SP+2–>SP,SP becomes 0014H

### Experiment 5 in assembly language (Wang Shuang), after completing the fifth and sixth questions, analyzing and summarizing all the code line by line, as well as segmentation

Experiment 5 Writing and debugging a program with multiple segments

—————————————–

(1)

1. Keep the same

2. <Considering different machine environments, the answer cannot be standardized>

3. X-2, X-1

(2)

1. Keep the same

2. <Considering different machine environments, the answer cannot be standardized>

3. X-2, X -1

4.(N/16+1)*16 [Note: N/16 takes only the integer part]

(3)

1. Remain unchanged

2. <Considering different machine environments, the answer can not be standardized>

3. X+3, X+4

(4)

Answer: no. 3 can still be executed correctly. This is because the compiler executes the program sequentially if the end instruction is followed by the removal of the label start. In other words, the compiler automatically compiles and executes the source program in ‘top-down’ order when it is not given advance notice of where to start executing the program.

(5) The complete program is as follows:

assumecs:code

asegment

db1,2,3,4,5,6,7,8

aends

bsegment

db1,2,3,4,5,6,7,8

bends

csegment

db0,0,0,0,0,0,0,0,0

cends

codesegment

start:movax,a

moves,ax

movax,c

movds,ax

movbx,0

movcx,8

s1:movax,es:[bx]

loops1

movax,b

moves,ax

movds,ax

movbx,0

movcx,8

s2:movax,es:[bx]

loops2

movax ,4c00h

int21h

codeends

endstart

(6) The complete program is as follows:

assumecs:code

asegment

dw1,2,3,4,5,6,7,8

< p>aends

bsegment

dw0,0,0,0,0,0,0,0,0

bends

codesegment

start:

movax,b

movss,ax

movsp int21h

codeends

endstart

Experiment 6 Programs from the practice session

——————————-

(2) Programming: complete the program in the problem.

The complete program for Problem 7.9 is as follows:

assumecs:codesg,ss:stacksg,ds:datasg

stacksgsegment

dw0,0,0,0,0,0,0,0,0

stacksgends

< p>datasgsegment

db’1.display’

db’2.brows’

db’3.replace’

db’4.modify’

datasgends

codesgsegment<

start:

movax,stacksg

movss,ax

movsp,16

movax,datasg

movds,ax

movbx,0

movcx,4

s:;outer loop

pushcx

movsi,3

movcx,4

s0:;inner loop

moval,[bx+si]

andal,11011111b

mov[bx+si],al

incsi

loops0

popcx

loops

movax,4c00h

int21h

codesgends

endstart

### Wang Shuang’s assembly language experiment begs for guidance ah

Code segment 1505:0000 – 1507:0001,

(where the last sentence movax,4c00 takes up three bytes and INT21 takes up one byte).

Then all of 1505 is used, all of 1506 is used, and the first two bytes of 1507 are used.

As mentioned on the first floor, even if only one byte is used, the segment address of the next segment should be increased by 1.

So the data and stack segments are 1508 and 1509.

And what you said about 1505:00-1505:19 can actually be converted to 1505:00-1506:09