Home > Blockchain >  What arguments can be submitted for the macro so that the program worked without errors?
What arguments can be submitted for the macro so that the program worked without errors?

Time:11-03

I recently started studying this topic, I'm still confused, what arguments to submit when calling mReadAX?

According to the assignment, this macro should enter an integer into the AX register in the 10-digit number system.

Here is the macro itself.

mReadAX macro buffer, size
local input, startOfConvert, endOfConvert
    push bx
    push cx
    push dx
input:
    mov [buffer], size
    mov dx, offset [buffer]
    mov ah, 0Ah
    int 21h

    mov ah, 02h
    mov dl, 0Dh
    int 21h

    mov ah, 02h
    mov dl, 0Ah
    int 21h

    xor ah, ah
    cmp ah, [buffer][1]
    jz input

    xor cx, cx
    mov cl, [buffer][1]
    xor ax, ax
    xor bx, bx
    xor dx, dx
    mov bx, offset [buffer][2]
    cmp [buffer][2], '-'
    jne startOfConvert
    inc bx
    dec cl
startOfConvert:
    mov dx, 10
    mul dx
    cmp ax, 8000h
    jae input
    mov dl, [dx]
    sub dl, '0'
    add ax, dx
    cmp ax, 8000h
    jae input
    inc bx
    loop startOfConvert
    cmp [buffer][2], '-'
    jne endOfConvert
    neg ax
endOfConvert:
    pop dx
    pop cx
    pop bx
endm mReadAX

CodePudding user response:

The macro uses the DOS.BufferedInput function 0Ah. Read the fine detail about this function in How buffered input works.

what arguments to submit when calling mReadAX?

  • The buffer argument needs to be the offset address of a portion of memory large enough to hold the required input structure.
  • The size argument needs to be a byte-sized value [1,255] that determines how many characters the input is allowed to process.

eg. If you want to allow a 5-digit input then set size=6. That's 1 more (than 5) because you need to allow for the addition of a terminating carriage return. In this case the buffer argument must point to a memory buffer of 8 bytes. That's again 2 bytes more because the 1st byte will receive the size value and the 2nd byte serves to return to you the length of the actual input.

I did not analyze the macro code itself too much since I presume it was given in the assignment and therefore ought to be correct. Sadly I found an error/typo on mov dl, [dx]. This must become mov dl, [bx].

The allowed input range is [-32767,32767]. Therefore the minimal value for your size argument is 7.

size    equ 7
buffer  db  size, 0, size dup(0)
  • Related