1

A decimal number of N digits ending with $ is read from the keyboard. (N<10). Print the number of digits of the number and its mathematical parity in an emu8086 program (ASM).

I can't seem to understand what I am doing wrong. Is "input" an invalid instruction? How can i read a number from the keyboard in assembly?

numCifre db 0

start:
    input number

    mov cx, 0
    .numaraCifre:
        mov ax, number
        xor dx, dx
        div byte 10
        inc cx
        cmp ax, 0
        jne .numaraCifre

    mov dl, cl
    add dl, '0'
    mov ah, 0Ah
    int 21h

    mov ax, number
    and ax, 1
    jz .par
    mov dl, 'I'
    jmp .showParity
    .par:
        mov dl, 'P'
    .showParity:
        mov ah, 0Ah
        int 21h

    mov ax, 4C00h
    int 21h
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
mimimi
  • 11
  • 1
  • 3
    There's no `input` instruction. There's an `in` instruction, but it accepts data from a port, so think a single byte, for example, rather than a sequence of bytes representing a number (further you'd have to have a device hooked up to a port to use it). There may be a library function you can call to do input in your environment. Otherwise, you need to look to the services of int 21h. – Erik Eidt Jan 06 '23 at 16:23
  • 2
    If you add an `include emu8086.inc` at the top there are some macros in EMU8086 that may help like `GET_STRING`. Instructions on using those macros can be found here: https://jbwyatt.com/253/emu/asm_tutorial_05.html – Michael Petch Jan 06 '23 at 18:07
  • 1
    If you want the decimal digits of a number, probably easier to just read it as a string in the first place. If you mean even/odd (not the [tag:parity] tag), that only depends on the low bit or the low decimal digit (since base 10 is a multiple of 2), so you never need the whole number as a binary integer, just an ASCII string is fine. A 10-digit number won't always fit in 16 bits. – Peter Cordes Jan 07 '23 at 09:35

1 Answers1

2

Is "input" (input number) an invalid instruction?

It is certainly not an instruction. It could possibly be a macro, if one were defined so...

How can i read a number from the keyboard in assembly?

Inputting multi-radix multi-digit signed numbers with DOS explains this and even has a DeLuxe version on offer.
However, for your particular task

A decimal number of N digits ending with $ is read from the keyboard. (N<10).

it will be a simple matter of inputting single digits (up to 9 of them):

  xor  cx, cx
Again:
  mov  ah, 01h    ; DOS.GetKeystroke
  int  21h        ; -> AL
  cmp  al, '$'
  je   Done
  cmp  al, '0'
  jb   Again      ; Not a digit
  cmp  al, '9'
  ja   Again      ; Not a digit
  mov  bl, al     ; Remember the last (least significant) digit
  inc  cx
  cmp  cx, 9
  jb   Again
Done:

Print the number of digits of the number and its mathematical parity in an emu8086 program (ASM).

Because the number of digits is between 0 and 9, printing the value is almost like you did it except that you were using the wrong function number 0Ah.

  mov  dl, cl     ; [0,9]
  add  dl, '0'    ; -> ["0","9"]
  mov  ah, 02h    ; DOS.PrintCharacter
  int  21h

For the mathematical parity (aka even/odd), you only need to consider the least significant digit of the number. That's why in the above input routine I stored the last digit in the BL register.

  mov  dl, 'P'
  shr  bl, 1      ; Inspecting the lowest bit of the last digit
  jnc  IsEven
  mov  dl, 'I'
IsEven:
  mov  ah, 02h    ; DOS.PrintCharacter
  int  21h

In your .numaraCifre div byte 10 is wrong. An immediate operand is not possible, and even if 10 were referring to a memory variable (with emu8086 it wouldn't surprise me) it would still have to be a word instead of a byte.

Sep Roland
  • 33,889
  • 7
  • 43
  • 76
  • when i changed the function from 0Ah to 02h it only gave me an ASCII character instead of printing it right. is there no other function to print more than 1 digit? – mimimi Jan 08 '23 at 20:54