You need to enable JavaScript to run this app. 基于Irvine32库的汇编如何实现字符后移、大小写反转与字符串逆序
优惠活动
大模型
产品
解决方案
定价
更多

基于Irvine32库的汇编如何实现字符后移、大小写反转与字符串逆序

Irvine32库32位汇编字符串组合处理实现问题

核心实现目标

需要对用户输入的字符串同时完成三类操作:

  • 整体逆序输出
  • 每个英文字符替换为字母表中紧邻的下一位对应字母
  • 字符大小写与原状态完全相反
  • 参考效果:输入Test时,预期输出为UTFu

现有待改造代码

INCLUDE Irvine32.inc
INCLUDELIB Irvine32.lib
 
.data
    buffer byte 128 dup(0)
    msg1   byte  "Enter a string of at most 128 characters:", 0dh, 0ah, 0
    msg2   byte  " Here it is in LOWERCASE and in reverse order: ", 0dh, 0ah, 0
    msg3   byte   0dh, 0ah, " There are ",0
    msg4   byte  " lower-case characters ", 0dh, 0ah, 0
    countLower byte 0
 
.code
    main PROC
 
    mov ecx, 0
    mov eax, 0
    mov edx,OFFSET msg1
    call WriteString

    read_again:
       cmp ecx, 128
       ja endread

    call ReadChar
    cmp al, 0Dh
    je display
    cmp al, 61h
    jae test_lower
    cmp al, 41h
    jb store
    cmp al, 5Ah
    ja store
    add al, 20h
    inc countLower
    ja store

   test_lower :
    cmp al, 7Ah
    ja store
    sub al, 20h

   store:
    push eax
    inc ecx
    jmp read_again

   endread:
    lea esi, buffer

   display :
    jecxz quit
    mov edx, OFFSET msg2
    call WriteString

   again: 
    pop eax
    call WriteChar
    loop again
    mov edx, OFFSET msg3
    call WriteString
    movzx eax,countLower
    call WriteDec
    mov edx, OFFSET msg4
    call WriteString

   quit:
 
   exit
   main ENDP
END main

现有代码的逻辑偏差

  • 仅实现了大小写反转逻辑,缺失“英文字母后移一位”的核心转换规则
  • 未处理字母边界场景:比如大写'Z'、小写'z'位移后需要绕回对应字母表首位的逻辑
  • 原有代码绑定了旧版“输出全小写、统计小写字符数”的需求逻辑,和当前新需求的输出规则不匹配
  • 现有压栈逻辑天然适配逆序输出(栈为后进先出结构),只需在压栈前完成字符规则转换即可复用现有输出流程

内容的提问来源于stack exchange,提问作者Lawrence_matei

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.18 12:54:00