【问题标题】:need additional string operations for my assembly language tasm tlink [closed]我的汇编语言 tasm tlink 需要额外的字符串操作 [关闭]
【发布时间】:2017-09-29 15:28:23
【问题描述】:

对不起,我对技术术语很弱哈哈需要帮助!在此处添加大约 5 个字符串操作或至少可以添加的操作,我需要 10 个选项,谢谢!

Data Segment
 chc db 0dh,0ah,"Choose Operation: $"
 chc1 db 0dh,0ah," 1. Accept String $"
 chc2 db 0dh,0ah," 2. Display String $"
 chc3 db 0dh,0ah," 3. Display Length $"
 chc4 db 0dh,0ah," 4. Display Reverse $"
 chc5 db 0dh,0ah," 5. Check Palindrome $"
 chc6 db 0dh,0ah," 6. Exit $"
 len db ?
 msg db 0dh,0ah,"Please enter the String: $"
 msg1 db 0dh,0ah,"The length of the entered String is: $"
 msg2 db 0dh,0ah,"The entered String is: $"
 msg3 db 0dh,0ah,"The reverse of the entered String is: $"
 pal db 0dh,0ah,"The String is a Palindrome. $"
 npal db 0dh,0ah,"The String is not a Palindrome. $"
 newl db 0dh,0ah," $"
Data ends
Code Segment
 assume DS:Data,CS:Code
Start:
 mov ax,Data
 mov DS,ax

 call AcceptString

l: mov dx,offset chc
 mov ah,09h
 int 21h
 mov dx,offset chc1
 mov ah,09h
 int 21h
 mov dx,offset chc2
 mov ah,09h
 int 21h
 mov dx,offset chc3
 mov ah,09h
 int 21h
 mov dx,offset chc4
 mov ah,09h
 int 21h
 mov dx,offset chc5
 mov ah,09h
 int 21h
 mov dx,offset chc6
 mov ah,09h
 int 21h

 mov dx,offset newl
 mov ah,09h
 int 21h

 mov ah,01h
 int 21h
 sub al,30h

 cmp al,06h
 jz ex

 cmp al,05h
 jne n1
 call CheckPal

n1: cmp al,04h 
 jne n2
 call DisplayRev

n2: cmp al,03h 
 jne n3
 call DisplayLength

n3: cmp al,02h 
 jne n4
 call DisplayString

n4: cmp al,01h
 jne l
 call AcceptString 
 jmp l

ex: mov ah,4ch
 int 21h
AcceptString proc
 mov si,1000h
 mov di,1000h
 mov cx,0000h

 mov dx,offset msg
 mov ah,09h
 int 21h

    back: 
 mov ah,01h
 int 21h

 cmp al,0dh
 je comp
 inc cx
 mov [si],al
 mov [di],al
 inc si
 inc di
 jmp back
comp: mov len,cl
 ret
endp
DisplayString proc
 mov dx,offset msg2
 mov ah,09h
 int 21h

 mov cl,len
 mov ch,00h
 mov si,1000h

    disp: 
 mov dl,[si]
 mov ah,02h
 int 21h

 inc si
 loop disp
 ret
endp
DisplayLength proc
 mov dx,offset msg1
 mov ah,09h
 int 21h

 mov bl,len
 call DispNum
 ret
endp
DispNum proc
 mov al,bl
 and al,0f0h
 ror al,1

 mov dl,al
 call HexDisp
 mov ah,02h
 int 21h

 mov al,bl
 and al,0fh

 mov dl,al
 call HexDisp
 mov ah,02h
 int 21h
endp
HexDisp proc
 cmp dl,0ah
 jc nothex
 add dl,07h
 nothex: add dl,30h
 ret
endp
DisplayRev proc
 mov dx,offset msg3
 mov ah,09h
 int 21h

 mov cl,len
 mov ch,00h
 mov si,1000h
 add si,cx
 dec si

     dispr: 
 mov dl,[si]
 mov ah,02h
 int 21h

 dec si
 loop dispr
 ret
endp
CheckPal proc
 mov al,len
 mov ah,00h
 mov bl,02h
 div bl
 mov cl,len
 dec cl
 mov ch,00h
 mov di,1000h
 mov si,1000h
 add di,cx
 mov cl,al
 mov ch,00h

     pchk: 
 mov al,[si]
 cmp al,[di]
 jnz np
 inc si
 dec di
 loop pchk

 mov dx,offset pal
 mov ah,09h
 int 21h
 ret

      np: 
 mov dx,offset npal
 mov ah,09h
 int 21h
 ret
endp
Code ends
end Start

【问题讨论】:

  • 请您有足够的责任至少检查您发布的内容是否格式正确。避免“复制粘贴然后忘记”的态度。无论如何,您的帖子似乎漏掉了一个问题。
  • 通过快速阅读您的代码.. 您还应该找一些经验丰富的讲师与您一起审查您的代码,指出您那里的所有错误,并在扩展之前先修复它.您的代码中存在一些严重的误解,如果它对您有效,那么这是一种幸运的巧合。

标签: assembly


【解决方案1】:

如果您需要在菜单中添加 5 个选项,例如,您可以为这些选项编写代码:

  • 全大写显示字符串
  • 显示大写颠倒的字符串(“Hello” -> “hELLO”)
  • 显示字符串已删除空格(“hi jack!” -> “hijack!”)
  • 显示字符串是否为有效整数值(有效字符只有“+”或“-”开头,然后只有数字,至少有一个数字)
  • 字符串中字母“a”的显示计数
  • 删除所有字母“a”的显示字符串
  • 显示所有字母“aeiouy”变成“-”的字符串(当您尝试编写“hangman”游戏时可能会很方便)
  • ROT13 "encryption"
  • 计算字符串中的字母/单词/换行符

如果您想要更大的挑战,例如,您可以显示字符串中多次出现的所有单词(甚至作为子字符串),例如“让字母形成调色板”。 ->“让:字母,调色板”。 (前面几个都比较简单,这个就比较费劲了,4-10个那么简单)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多