输入的字符串EMU8086变化情况,并扭转 [英] emu8086 change case of the entered string and reverse it
问题描述
我在汇编语言程序设计全新的,我坚持在我需要改变输入的字符串的情况下,再加上扭转字符串,以及一个问题。我使用EMU8086。我下面code,我要么能够改变的情况下或反向的字符串。但我需要同时进行这两种操作。
I am totally new in assembly language programming and I am stuck with a problem in which I need to change case of the entered string plus reverse the string as well. I am using emu8086. I the following code I am either able to change case or reverse the string. but I need to perform both the operations simultaneously.
.MODEL CASECHANGE
.DATA
MSG1 DB 0DH,0AH, 'Enter string:$'
MSG2 DB 0DH,0AH, 'String in reverse case:$'
STR1 DB 255 DUP(?)
.CODE
START:
MOV AX,@DATA
MOV DS,AX
LEA DX,MSG1
MOV AH,09H
INT 21H
LEA SI,STR1
MOV AH,01H
jz offsets
GET:
INT 21H
MOV BL,AL
CMP AL,0DH
JE SET
XOR AL,20H
MOV [SI],AL
INC SI
JMP GET
SET:
MOV AL,'$'
MOV [SI],AL
LEA DX,MSG2
MOV AH,09H
INT 21H
LEA DX,STR1
MOV AH,09H
INT 21H
MOV AL,09H
JMP START
JMP BACK
.EXIT
低于code字符串逆向以上code变化的情况下,我需要参加两个codeS以达到所需的输出。
below code reverse the string and above code changes case and I need to join both codes to achieve desired output.
BACK:
int 21h
MOV BL,AL
cmp al,0dh
jz exit
mov [si],al
inc si
inc ch
jmp back
EXIT:
lea dx,MSG2
mov ah,09h
int 21h
cmp1:
mov al,[si]
mov dl,al
mov ah,02h
int 21h
dec si
dec ch
jnz cmp1
mov ah,01ch
int 21h
OFFSETS:
mov ch,01h
mov si,offset STR1
END START
这2套codeS是由我的老师提供的所以只能用这个code玩。
These 2 set of codes are provided by my instructor so can only play with this code.
推荐答案
我真的不读你注释掉code的大规模墙。
I didn't really read your massive wall of uncommented code.
要扭转就地缓冲液,获得的指针的第一个和最后字符,则:
To reverse a buffer in-place, get pointers to the first and last characters, then:
-
加载字节到寄存器,然后存储对面寄存器回指针。
Load the bytes into registers, then store the opposite registers back to the pointers.
递增的开始指针 SI
,递减结束指针迪
。
Increment the start pointer si
, decrement the end pointer di
.
环路只要启动<结尾: CMP SI,DI / JB
loop as long as start < end: cmp si, di / jb
Downcasing可以在单个字符来完成,这样你就可以做的两个单独字节,当你在寄存器中有他们,而你交换。只要检查它的之间的'A'
和'Z'
,然后加为0x20。 (不幸的是你不能只是或人,20H
除非你的知道的你的角色已经不是一个较低或大写字母,而不是其他一些ASCII字符)。
Downcasing can be done on a single character, so you can do that on both bytes separately, when you have them in registers while you're swapping. Just check that it's between 'A'
and 'Z'
, then add 0x20. (You unfortunately can't just or al, 20H
unless you know that your character is already either a lower or uppercase letter, and not some other ASCII character).
倒车到一个新的缓冲区更容易。刚向前走在一个阵列和向后另一方面,为计数
字节。
Reversing to a new buffer is even easier. Just go forwards in one array and backwards in the other, for count
bytes.
如果你的目标基准CPU功能集包括386指令,你可能会在启动时加载4B和使用 BSWAP
在一个时间来扭转字节4。或用SSSE3, PSHUFB
来一次逆转16B。
If your target baseline CPU feature set included 386 instructions, you could have loaded 4B at a time and used bswap
to reverse bytes 4 at a time. Or with SSSE3, pshufb
to reverse 16B at a time.
这篇关于输入的字符串EMU8086变化情况,并扭转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!