Assembly 如何在部件x86中将2位数字连接到数字中

Assembly 如何在部件x86中将2位数字连接到数字中,assembly,x86,x86-16,Assembly,X86,X86 16,我在汇编中有这个任务来做一些游戏,对于这个游戏,我需要从数组中获取两个数字,并将其转换为一个数字,比如如果我有2,3我需要将其转换为23,我该如何做?我真的不知道如何才能提供更多的信息,如果你能告诉我如何帮助你,我将很高兴 从注释中,我可以看到汇编可以保存字符串变量,我不知道怎么做,但我想这会容易得多,数组中的项目是int值(我想),下面是游戏代码: IDEAL MODEL small STACK 100h DATASEG CODESEG Clock equ es:6Ch ;Memor

我在汇编中有这个任务来做一些游戏,对于这个游戏,我需要从数组中获取两个数字,并将其转换为一个数字,比如如果我有
2,3
我需要将其转换为
23
,我该如何做?我真的不知道如何才能提供更多的信息,如果你能告诉我如何帮助你,我将很高兴

从注释中,我可以看到汇编可以保存字符串变量,我不知道怎么做,但我想这会容易得多,数组中的项目是int值(我想),下面是游戏代码:

IDEAL
MODEL small 
STACK 100h
DATASEG

CODESEG
Clock equ es:6Ch    ;Memory location of timer
ran db 0 
user_choice db 0 
computerscore db 0 
userscore db 0  
userw db 'you win',10,13,'$'
computerw db 'you lose',10,13,'$'
message db 5 dup (?)
lengthi dw ?
firstMsg db 'Enter the maximum number that the computer can draw (the max is 2 digits):',10,13,'$'
MACRO Random_Generator maxval
    mov ax,40h
    mov es,ax
    mov ax,[Clock]
    mov ah,[byte cs:bx]
    xor al,ah
    xor ah,ah
    and al,maxval
endm Random_Generator
proc lineBreak
    MOV dl, 10
    MOV ah, 02h
    INT 21h
    MOV dl, 13
    MOV ah, 02h
    INT 21h
    ret
endp lineBreak
start:
    mov ax, @data
    mov ds, ax
    ;;;;;;;;;;;;;;;;;;;;;;
    push seg firstMsg
    pop ds
    mov dx, offset firstMsg
    mov ah, 9h
    int 21h
    mov dx, offset message
    mov bx, dx
    mov [byte ptr bx], 3
    mov ah, 0Ah
    int 21h
    call lineBreak
    Random_Generator 9
    mov [ran],al
    mov ah,1
    int 21h
    sub al,30h
    ;mov [user_choice],al
    mov ah,[ran]
    cmp ah,al
    jne computerpoint
    inc [userscore] 
    mov dl,'*'
    mov ah,2
    int 21h
    cmp [userscore],1
    jb start
    je userwin
    computerpoint:
    inc [computerscore]
    cmp [computerscore],1
    jb start
    je computerwin
    userwin:
    call lineBreak
    push seg userw
    pop ds
    mov dx, offset userw
    mov ah, 9h
    int 21h
    jmp exit
    computerwin:
    call lineBreak
    push seg computerw
    pop ds
    mov dx, offset computerw
    mov ah, 9h
    int 21h
exit:
mov ax, 4c00h
int 21h
END start
以下是阵列的一部分:

message db 5 dup (?)
mov dx, offset message
mov bx, dx
mov [byte ptr bx], 3
mov ah, 0Ah
int 21h
如果有关系,我需要的数字,用户可以说什么是计算机可以绘制的最大数字

如果目的是允许用户输入1位数字或2位数字,则将缓冲区大小限制为3是可以的。
需要做的是检查是否收到了数字以及收到了多少数字。您将在
[bx+1]
的第二个字节中找到此计数

Input:
    mov  dx, offset message
    mov  bx, dx
    mov  byte ptr [bx], 3
    mov  ah, 0Ah
    int  21h
    mov  ax, [bx + 2]          ;Optimistically reading 2 digits
    sub  ax, "00"              ;Optimistically going from text to number
    cmp  byte ptr [bx + 1], 1  ;This byte could be 0, 1, or 2
    jb   Input                 ;Redo
    je   OneDigit
TwoDigits:
    xchg al, ah                ;Put tens in AH, put ones in AL
    aad                        ;Does AH * 10 + AL 
OneDigit:

您的最大数字现在位于
AL

我的程序集已生锈,但这可能会有所帮助:假设您使用的是十进制数字系统,将两个数字串联在一起等于将第一个数字乘以十,然后将结果添加到第二个数字。这个答案应该可以帮助您实现一个具体的实现:a..b=('0'+a)您是在尝试将一个2位数的字符串解析为一个整数,还是只是在尝试将两个单独的字节连接成一个2字节的字符串?后者很简单:
movzx-dx,字节ptr[低位字节]
/
mov-dh[高位字节]
Input:
    mov  dx, offset message
    mov  bx, dx
    mov  byte ptr [bx], 3
    mov  ah, 0Ah
    int  21h
    mov  ax, [bx + 2]          ;Optimistically reading 2 digits
    sub  ax, "00"              ;Optimistically going from text to number
    cmp  byte ptr [bx + 1], 1  ;This byte could be 0, 1, or 2
    jb   Input                 ;Redo
    je   OneDigit
TwoDigits:
    xchg al, ah                ;Put tens in AH, put ones in AL
    aad                        ;Does AH * 10 + AL 
OneDigit: