Assembly Language 4

Source: Internet
Author: User

Program 0: Convert the string "Adcdef" to uppercase, and change the string "FGHJK" to lowercase

Data segment
DB ' Adcdef '
DB ' xcvbnm '
Data ends


Code segment

Start
MOV Ax,data
MOV Ds,ax

MOV bx,0
MOV cx,6
MOV di,0

S:mov AL,DS:[BX]
and al,1011111b
MOV Ds:[bx],al

MOV al,ds:[bx+6]
or al,0100000b
MOV Ds:[bx+6],al
Add bx,1
Loop s


MOV ax,4c00h
int 21h
Code ends
End Start


Program 1: Use stack reverse to store DW 0111h,0222h,0333h,0444h,0555h,0666h,0777h,0888h
Assume Cs:code, Ds:data, Ss:stack
Data segment
DW 0111h,0222h,0333h,0444h,0555h,0666h,0777h,0888h
Data ends


Stack segment
DW 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Stack ends

Code segment

Start
MOV Ax,data
MOV Ds,ax

MOV Ax,stack
MOV Ss,ax
mov sp, 020h

MOV bx,0
MOV cx,8
MOV si,0
S:push [bx + si]
Add si,2
Loop s


MOV si,0
MOV cx,8
s1:pop [bx + si]
Add si,2
Loop S1

MOV ax,4c00h
int 21h
Code ends
End Start


Program 2: Define 6 Characters of data stored in cs:0 C unit, accumulate in ax
Assume CS:CODESG
CODESG segment

DW 0123h,0e32h,0a21h,0c43h,0344h,0544h

Start
MOV bx,0
MOV cx,6
MOV ax,0
S:add AX,CS:[BX]
Add bx,2
Loop s

MOV ax,4c00h
int 21h
CODESG ends
End Start


MOV ax,datasg
MOV Ds,ax
MOV bx,0

MOV cx,5
S:mov AL,0[BX]
and al,11011111b
MOV 0[bx],al
MOV AL,5[BX]
or al,00100000b
MOV 5[bx],al
Inc BX
Loop s

Program 3: Copy ffff:0-b data to 200-20b by byte
Assume CS:CODESG
CODESG segment

MOV bx,0
MOV cx,12
MOV AX,0FFFFH
MOV Ds,ax

MOV ax,0020h
MOV Es,ax

S:mov DL,[BX]
MOV es:[bx],dl
Inc BX
Loop s

MOV ax,4c00h
int 21h
CODESG ends
End


Program 4: Data of the Operation Ffff:0-b and storage DX
Assume CS:CODESG
CODESG segment

MOV AX,0FFFFH
MOV Ds,ax
MOV dx,0
MOV bx,0
MOV cx,12

S:add AL,[BX]
MOV ah,0
Add Dx,ax
Inc BX
Loop s

MOV ax,4c00h
int 21h
CODESG ends
End

Program 5: Complete the following program so that it can copy the 8 words in the 10000H~1000FH in reverse order to 20000H~2000FH.
mov ax, 2000H
MOV ds, ax
MOV ax,1000
MOV Ss,ax
MOV sp,0
Pop [E]
Pop [C]
Pop [A]
Pop [8]
Pop [6]
Pop [4]
Pop [2]
Pop [0]

program 6: In Debug, "D 0:0 1f" to see the memory, the results are as follows
1000:0000  8E C1 36 52 73 70 65 63-69 66 69 65 64 20 69  . 6Rspecified fi
1000:0010  6C 6E, 6D, 0D 0a-20, 20   lename.

MOV ax,1000
MOV Ds,ax
MOV ax,[0000] ax=c18e
MOV bx,[0001] Bx=36c1
MOV ax,bx AX=36C1
MOV ax,[0000] ax=c18e
MOV bx,[0002] bx=5236
Add AX,BX ax=13c4
Add ax,[0004] ax=8437
MOV ax,0 ax=0000
MOV al,[0002] ax=0036
MOV bx,0 bx=0
MOV bl,[000c] bx=0064
Add AL,BL ax=009a


MOV ax,1000
MOV Ds,ax
MOV ax,2000
MOV Ss,ax
MOV sp,10
Push Ds[0]
Push Ds[2]
Push Ds[4]
Push Ds[6]
Push Ds[8]
Push Ds[a]
Push Ds[c]
Push Ds[e]


Program 7: After the execution of the following 3 instructions, the CPU changes the IP several times? When was it all? What is the value in the last IP?
MOV AX,BX
SUB AX,BX
JMP AX

A: Modified 4 times ip=+2, ip=+2,ip=+2,ip=0
Analysis:
Suppose cs=1500 ip=0100
First time
Cs:ip points to 15100 memory, read the instruction mov ax,bx, at this time the IP is =102,cs unchanged.
Second time
Cs:ip points to 15102 memory, reads the instruction sub AX,BX, at which time the IP is =104,cs unchanged.
Third time
Cs:ip point to 15104 memory, read instruction in jmp AX, IP changed to =106 (for next point to memory)
Fourth time to execute JMP AX ip=0


Program 8:1. The address of the given segment is 0001H and only by changing the offset address, the CPU has a range of (00010) to (1000F) addressing.

Analysis: The offset address is 16 bits, the range is 0000--ffff, given the segment address then there is 0001*16+0000 to 0001*16+ffff, that is, 00010 to 1000F.


2. There is a data stored in the memory 20000h unit, now given the segment address SA, if you want to use offset address to find this unit.
The SA should satisfy the following criteria: Minimum is (1001), Maximum is (2000)

Analysis: Minimum value: 20000-ffff=10001
10001*16 is obviously more than 20000, it should be 1001.
1001*16+fff0=20000

Maximum value: (20000-0)/16=2000

Assembly Language 4

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.