HELP -New student - question on syntax for input string and bit operat

Started by ivanhuk, December 15, 2006, 10:13:34 PM

Previous topic - Next topic

ivanhuk

 :dazzled:

Hey,

I am having trouble figuring out how to enter a string of characters into an array one character at a time using int 21, 01h. 
I can do it using the 0ah function, but I need to process it one character (byte) at a time.  This should be simple but for some reason it only reads in one character then falls out:  The code I tried:

         sub  si, si
         mov bx, OFFSET string_to_enter_into
         prompt to enter msg end with null byte
TOP:  mov ah, 01h    ; read in character
         int   21h
         mov [bx + si], al
         inc   si
         cmp al, 0b       ; see if null character in byte if so end
         jne TOP
       
         print the new string

And Also how do you enter in a decimal number (using a function such as get_decimal which uses ax) and place that value as a bit within one single byte.  What I want to do is:

       read in decimal number 1 or 0 into ax
       shift that # left 7 times within ax
       enter in decimal number 1 or 0 into ax
       shift that # left 6 times within ax ....... and so on

       Print out the position and the number

I can't figure out the syntax do something like this, since everytime this would be done in a loop a new value is read into ax which wipes out the old value.  Any help MUCH Appreciated!!!!!!

       

kermit

hi,

1:

when you want to terminate the input with enter, simply compare "al" with 0Dh.
if you want the char "0" as terminator, you have to compare it with the asci value (=30h )
an example to play with:
.model tiny
.data
msg1 db "enter string and press enter",13,10,"$"
msg2 db "you entered:",13,10,"$"
input  db 20  dup ("$")
.code
.startup
         sub  si, si
         mov bx, OFFSET input
         lea dx,msg1
         mov ah,09
         int 21h
TOP:  mov ah, 01h    ; read in character
         int   21h
         mov [bx + si], al
         inc   si
         cmp al, 0dh       ; see if null character in byte if so end
         jne TOP
        lea dx,msg2
        mov ah,09
        int 21h
        lea dx,input
        int 21h
.exit
end

dont forget to terminate the string you want to display with "$" .

sry, i didn't understand the second question, maybe you want to enter a string of "0101..." and set the equivalent bits in ax register.
to set a bit one usually uses the "or" command, try to use a variable  to store the result, just a guess...


ivanhuk

Thanx for the help with the strings!  Much appreciated!! I finally figured it out.

What I am doing with the bitwise operators is I am trying to enter either a 1 or 0 thru a procedure which enters a decimal number in ax. I am trying to do this 8 times, so that in the end an 8 bit binary number is in al.  For instance, the first time I enter a one, then in a loop zero, then again in a loop 1...and so on...so that the final result is a binary number 101... in al.  However if I read in a 1 in ax, and then try to read in a zero again in ax, it obviously wipes out the number.  What I'll try is enter in ax, mov to bl, shl by 7, and then repeat, hopefully I am on the right track :-)

kermit

Hi,

Just do a "or al,1" or "or al,0" before, to set the last bit in al according to the user's input.
then simply make a "shl al,1"
repeat that 7 times and al should contain the result.

Of course u have to store "al" in a variable or on the stack, as each input with int21,01 will overwrite "al"  :P