-2

I have this task in assembly to do some game, for this game I need to get two numbers from array and make the to one number, like if I have 2, 3 i need to make it 23, how can i do it? I don't know really how can I give more information, I will glad if you can tell me how to help you.

from the comment I can see that assembly can hold string variables, I don't know how to do it but I guess it will be much easier, the items in the array are int values (I think), here is the game code:

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

here's the part of the array:

message db 5 dup (?)
mov dx, offset message
mov bx, dx
mov [byte ptr bx], 3
mov ah, 0Ah
int 21h

if it matter, I need the numbers for the user can say what's the max number that the computer can draw

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
S. josh
  • 79
  • 7
  • 2
    My assembly is rusty, but this may help: assuming you're working in a decimal number system, concatenating two digits together is the same as multiplying the first by ten, and adding that result to the second digit. This answer should help you with a concrete implementation: https://stackoverflow.com/a/20499363/492759 – Joseph Redfern Aug 22 '17 at 23:19
  • a..b = ( '0' + a ) << 8 + ( '0' + b ) – sivizius Aug 23 '17 at 02:49
  • Are you trying to parse a 2-digit string into an integer, or are you just trying to concatenate 2 separate bytes into a 2-byte string? The latter is trivial: `movzx dx, byte ptr [low_byte]` / `mov dh, [high_byte]` – Peter Cordes Aug 23 '17 at 21:54

1 Answers1

0
mov dx, offset message
mov bx, dx
mov [byte ptr bx], 3
mov ah, 0Ah
int 21h

If the aim is to allow the user to input either a 1-digit number or a 2-digit number, limiting the buffer size to 3 is fine.
What needs to be done is checking if and how many digits were recieved. You'll find this count in the second byte at [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:

Your maximum number is now in AL.

Sep Roland
  • 33,889
  • 7
  • 43
  • 76