Assign value to a variable in Assembly 8086

Asked

Viewed 1,582 times

1

I have the variable:

simbolo db "0 $"

and I also have the following function::

  read_keyboard:
  mov ah, 1
  int 21h
  ret

Which is a simple interruption that reads from the telado, and saves what was read in AH.

My problem is: how do I load the content of AH (keyboard read) in my variable symbol?

have tried:

mov simbolo, [AH]

and also

lea simbolo, AH

And I didn’t succeed.

1 answer

3


The function int 21,1 returns the character read in the register AL (and not in the AH).

To load the register value AL in memory position simbolo, use the command:

mov     [simbolo],al
  • The bracket indicates that simbolo is a memory position.

  • The origin (registrar al) is to the right of the comma, and the destination (simbolo) on the left, as per the intel syntax.

NOTE: the syntax of this command may change depending on the assembler you are using.

  • Thank you very much @Gomiero, everything worked out. But I read in some places saying that the interruption should be done the way I did, using in the first line the mov ah, 1. Could you explain to me why I should use this line? Since what is read is stored in AL.

  • @You’re welcome! The value in the register AH, setate before of the interrupt call, corresponds to the function that will be called. After the interruption, the result is obtained in the register AL. Each DOS function has a number (always placed in AH) and can: receive parameters and/or return results in other registers. Here is a link (in English) with the list of calls, parameters and returns: http://stanislavs.org/helppc/int_21.html

Browser other questions tagged

You are not signed in. Login or sign up in order to post.