In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "what is the realization method of string case conversion in assembly language". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations! I hope you can read it carefully and be able to achieve something!
Question 1: convert the first string in the data segment to uppercase and the second string to lowercase
Analysis:
How to convert to case
If you use ASCII code for conversion, you need to determine whether the character is uppercase or lowercase, assembly language implementation is too difficult, you can analyze the binary of the string.
In ASCII code, the fifth bit of uppercase letters is 0 and the fifth bit of lowercase letters is 1, which can be converted to uppercase and lowercase.
Assume cs:code,ds:datadata segment db 'BaSiC' db' InfoMaTion'data ends;--; practice 1: code segmentstart: mov ax,data mov ds,ax mov bx,0; set ds:bx to point to segment mov cx,5 Loop conversion s: mov al,ds: [bx] and al,11011111B for the first string; convert the fifth bit of the character to 0 and into uppercase letters mov ds: [bx], al inc bx loop s mov bx,5 Point to the second string mov cx,11s0: mov al,ds: [bx] or al,00100000B; convert the fifth bit of the character to 1 and into lowercase letters mov ds: [bx], al inc bx loop s mov ax,4c00h int 21hcode ends -- Practice two Improved version: using bx+idata to simplify the code code segmentstart: mov ax,data mov ds,ax mov bx,0 mov cx,5s: mov al,ds: [bx] and al,11011111b mov ds: [bx], al mov al,ds: [bx+5] or al 00100000b mov ds: [bx+5], al inc bx loop s code ends -- end start question 2: change the first letter of each word in the data paragraph to a capital letter
Analysis: how to implement a loop
If the data is structured, it can be seen as a two-dimensional array, using a variable to locate the row, and a constant to define the first letter.
Assume cs:code,ds:datadata segment db'1. File'db'2. Edit'db'3. Search 'data endscode segmentstart: mov ax,data mov ds,ax mov bx,0 Ds:bx specifies the data segment, while bx is used as the variable mov cx,3s: mov al,ds: [bx+3] that defines the row 3 as a constant, define the first letter and al,11011111b mov ds: [bx+3], al add bx,16 loop s mov ax,4c00h int 21hcode ends end question 3: change each word in the data paragraph to a capital letter
Analysis: 1. For this structured data, we need not only a variable definition row, but also a variable definition column.
Assume cs:code,ds:data,ss:stackdata segment db 'ibm' db 'dec' db 'vax' data ends; Practice 1: code segmentstart: mov ax,data mov ds,ax mov bx,0 mov cx,3s0: mov dx,cx; use the same variable to loop at the same time, and you need to save mov si,0 mov cx,3 to the value of the outer loop The number of times cx is set to inner loop s: mov al,ds: [bx+si] and al,11011111b mov ds: [bx+si], al inc si loop s add bx,16 mov cx,dx Use the outer loop stored in dx to restore the outer loop counter loop s0 mov ax,4c00h int 21hcode ends; -; practice 2, use the stack to save the value of the outer loop stack segment dw 8 dup (0) Use the stack segment to save the value of cx: stack endscode segmentstart: mov ax,stack mov ss,ax mov sp,16; ss:sp points to the stack segment mov ax,data mov ds,ax mov bx,0 Ds:bx points to the data segment mov cx,3s0: push cx mov si,0 mov cx,3s: mov al,ds: [bx+si] and al,11011111b mov ds: [bx+si], al inc si loop s add bx 16 pop cx loop s0 mov ax,4c00h int 21hcode ends -end start question 4: change the first four letters of each word in the data paragraph to uppercase letters
Analyze how to locate the contents of each string
Using bx+si+idata to locate the first letter
Assume cs:code,ds:data,ss:stackdata segment db'1. Display'db'2. Brows'db'3. Replace 'data endsstack segment dw 8 dup (0) stack ends code segmentstart: mov ax,stack mov ss,ax mov sp,16 mov ax,data mov ds Ax mov bx,0 mov cx 3 Setting the outer loop is only 3 lines s 0: push cx mov si,0 mov cx,4; setting the inner loop only takes 4 times s: mov al,ds: [bx+si+3] Set the first letter to be changed: and al,11011111b mov ds: [bx+si+3], al inc si loop s add bx,16 pop cx loop S0 mov ax,4c00h int 21hcode ends end start question 5: design a subroutine Convert a string full of letters to uppercase
Analysis: the design of the subroutine needs to pay attention to two problems: the content and length of the string
It is impossible to put all the contents of the string in the subroutine. You can consider putting the first address of the string in the subroutine. Use the loop to traverse the string, and the number of loops is the length of the string.
Assume cs:code,ds:datadata segment db 'conversation'data ends code segmentstart: mov ax,data mov ds,ax mov si,0; ds:si points to the first address mov cx,12 of the space in which the string resides Cx stores the length of the string call capital mov ax,4c00h int 21h capital: and byte ptr ds: [si], 11011111b inc si loop capital retcode ends end start problem 6: design a subroutine that will be full of letters A string that ends with 0, converted to uppercase
Analysis:
1. To process a string that ends with 0, you need to identify the 0 that ends.
Jcxz is used to determine whether the last character is 0.
2. The number of cycles cannot be known.
So you can't use loop, you can only use jmp to jump to the beginning of the loop.
Assume cs:code,ds:datadata segment db 'conversation',0data ends code segmentstart: mov ax,data mov ds,ax mov si,0 Ds:si points to the beginning of the segment call capital mov ax,4c00h int 21h capital: mov cl,ds: [si] mov ch,0 jcxz ok If the string is 0, it will jump out of the loop and byte ptr ds: [si], 11011111b inc si jmp short capital; jump to implement the loop ok: ret End loop code endsend start A more complex version of structured data, assume cs:code,ds:data,ss:stackdata segment db 'word',0 db' unix',0 db 'wind',0data endsstack segment db 8 dup (0) stack ends code segmentstart: mov ax,data mov ds,ax mov bx 0 mov cx,3 Outer loop to realize s: mov si,bx call capital add bx,5 Realization of inner loop loop s mov ax,4c00h int 21h capital: push cx push si change: mov cl,ds: [si] mov ch 0 jcxz ok and byte ptr ds: [si] 11011111b inc si jmp short change ok: pop si pop cx ret code endsend "what is the implementation of string case conversion in assembly language?" that's it. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.