使用 include 'emu8086.inc' 反轉字符串的大小寫和順序 (Reverse case and order of a String using include 'emu8086.inc')


問題描述

使用 include 'emu8086.inc' 反轉字符串的大小寫和順序 (Reverse case and order of a String using include 'emu8086.inc')

在以下代碼中,我可以反轉字符串,但我不知道如何在此代碼中添加函數以獲得以下結果:

輸入 AbCDeF_XYz 輸出:Zyx_fEdcBa

name "REVERSE"

include "emu8086.inc" 

      print "Enter a string:"
      MOV DX,11
      CALL get_string   
      printn
      MOV DI,0x0

ReadString:

      MOV AL,[ds+di]
      CMP AL,0x0
      JE Reverse
      INC DI
      PUSH AX
      JMP ReadString
Reverse:

      POP AX
      MOV AH,0xE
      INT 0x10
      CMP AL,0x0
      JNE Reverse

HLT

DEFINE_GET_STRING
END

參考解法

方法 1:

I can suggest these 3 solutions for your program:

  • In your push loop you should also push the zero because now your pop loop will not correctly find a finishing zero!

      MOV DI,0x0
    ReadString:
      MOV AL,[ds+di]
      INC DI
      PUSH AX
      cmp al, 0
      jne ReadString
    Reverse:
    
  • You can tackle the case swap by looking closely at the input string. It only has the underscore character _ that poses a problem. You'll have to test for it and then bypass the case swap:

      MOV DI,0x0
    ReadString:
      MOV AL,[ds+di]
      INC DI
      cmp al,"_"
      je  NoSwap
      xor al,32  ;This toggles lowercase and uppercase
    NoSwap:
      PUSH AX
      cmp al, 0
      jne ReadString
    Reverse:
    
  • In your current program you print the terminating zero. This is almost certainly not what you should do!

    Reverse:
      POP AX
      cmp al,0
      je  EndOfReverse
      MOV AH,0xE
      INT 0x10
      Jmp Reverse
    EndOfReverse:
      HLT
    

(by BhhooHDFifoernik)

參考文件

  1. Reverse case and order of a String using include 'emu8086.inc' (CC BY‑SA 2.5/3.0/4.0)

#emu8086 #assembly #x86-16 #x86 #dos






相關問題

使用 include 'emu8086.inc' 反轉字符串的大小寫和順序 (Reverse case and order of a String using include 'emu8086.inc')

emu8086 : ARR 不包含任何值 (emu8086 : ARR do not contain any value)

為什麼這個彙編代碼不刪除擴展名為“.lnk”的文件? (Why doesn't this assembly code delete the file with ".lnk" extension?)

將 C 代碼轉換為 8086 程序集 (Converting C code into 8086 assembly)

循環無法打印字母 (Loop does not work to print alphabets)

如何使用 call 和 ret 更改堆棧內容? (how to change stack content with call and ret?)

彙編語言中的putch函數通過堆棧 (putch function in assembly language through stack)

如何在不使用 HLT 的情況下對程序進行 HLT (How to HLT the program without using HLT)

使用 8086 彙編計算 10 的階乘 (Computing the factorial of 10 using 8086 assembly)

你好,我有一個問題,我需要從用戶那裡得到輸入,輸入是一個數字和一個數字後的數字,數字可以是雙字 (hello , i got a question that i need to get input from user, the input is a number and digit after digit ,the number can be a doubleWord)

在彙編語言中得到錯誤的結果 (Getting wrong result in Assembly language)

我的氣泡代碼是彙編語言嗎? (is my code for bubble right at assembly language?)







留言討論