flat assembler
Message board for the users of flat assembler.

Index > DOS > Input a WORD and store it into a register

Author
Thread Post new topic Reply to topic
denial



Joined: 12 Sep 2004
Posts: 98
denial 16 Oct 2004, 12:30
Hello Smile

Slowly I start to understand data handling in Assembler. Wink
Now I want to write an application, where the user can input a number. This number should then get stored into a 16-bit register, like AX.

How to make this?
I searched already and I found some threads about input routines, but I can't get them work for my purpose. Can you help me?

Thank you
denial
Post 16 Oct 2004, 12:30
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 16 Oct 2004, 18:55
I have written a keyboard scancode writer, here it is:

Code:
org $100
mainloop:

mov cx,1
call scroll80x25down ; CX = lines to scroll ( must be valid )

mov dx,press_key
xor bx,bx
mov cl,15
call writestring80x25 ; DX = address of string bl=x bh=y cl=color , 0 terminated

call breadkey
push ax

mov dh,15
mov dx,ax
xor bx,bx
mov bl,12
mov ch,15
call writehexword80x25 ; DL = byte input bl=x bh=y ch=color ( writes 2 nibbles from input )

mov dx,ascii_txt
mov cl,15
xor bx,bx
mov bl,18
call writestring80x25 ; DX = address of string bl=x bh=y cl=color , 0 terminated

pop ax
push ax

mov dl,ah
mov dh,15
xor bx,bx
mov bl,24
call write80x25 ; DL = Char to write DH = Color bl=x bh=y , returns: AX = DX, DI = offset
pop ax
push ax

mov dl,al
mov dh,15
xor bx,bx
mov bl,25
call write80x25 ; DL = Char to write DH = Color bl=x bh=y , returns: AX = DX, DI = offset

pop ax
cmp al,27
jne mainloop
mov dx,esc_key
mov cl,15
xor bx,bx
mov bl,30
call writestring80x25 ; DX = address of string bl=x bh=y cl=color , 0 terminated
int 20h

esc_key db 'Escape pressed',0
press_key db 'Press a key',0
ascii_txt db 'ascii',$3e,'  ',$3c,0

write80x25: ; DL = Char to write DH = Color bl=x bh=y , returns: AX = DX, DI = offset
push es
mov ax,$b800
mov es,ax

xor ax,ax
xchg al,bh   ;  mov ax,80
mov di,ax    ;  mul bh
shl di,2     ;  xor bh,bh
add di,ax    ;  add ax,bx
shl di,4     ;  shl ax,1
add di,bx    ;  mov di,ax
shl di,1

mov ax,dx
stosw
pop es
ret

writestring80x25: ; DX = address of string bl=x bh=y cl=color , 0 terminated string !
push es
mov ax,$b800
mov es,ax
mov si,dx

xor ax,ax
xchg al,bh   ;  mov ax,80
mov di,ax    ;  mul bh
shl di,2     ;  xor bh,bh
add di,ax    ;  add ax,bx
shl di,4     ;  shl ax,1
add di,bx    ;  mov di,ax
shl di,1

mov ah,cl
again:
lodsb
cmp al,0
je ext2
stosw
jmp again
ext2:
pop es
ret

writehexword80x25: ; DX = 16 bit input bl=x bh=y ch=color ( writes 4 nibbles from input )
push es                ; does not remove leading zeroes
mov ax,$b800
mov es,ax
xor ax,ax
xchg al,bh
mov di,ax
shl di,2
add di,ax
shl di,4
add di,bx
shl di,1
mov cl,4
.roll1:
rol dx,4
mov al,dl
and al,$f
cmp al,10
sbb al,69h
das
mov ah,ch
stosw
dec cl
jnz .roll1
pop es
ret

scroll80x25down: ; CX = lines to scroll ( must be valid )
push es
push ds
std
mov ax,$b800
mov ds,ax
mov es,ax
mov di,4000
mov ax,cx
shl ax,2
add ax,cx
shl ax,5
mov si,di
sub si,ax
mov dx,ax
mov ax,25
sub ax,cx
mov cx,ax
shl ax,2
add ax,cx
shl ax,3
xor ecx,ecx
mov cx,ax
inc cx
rep movsd
mov eax,$07200720
mov cx,dx
shr cx,2
rep stosd
cld
pop ds
pop es
ret

breadkey:  ;biosreadkey returns ax
mov ah,$10
int $16
ret
    
Post 16 Oct 2004, 18:55
View user's profile Send private message Visit poster's website Reply with quote
denial



Joined: 12 Sep 2004
Posts: 98
denial 16 Oct 2004, 20:29
Thank you,

that's a very impressive piece of code. I compiled it but the code isn't clear to me at all, at the moment. I'll try to understand it, and use it to solve my problem. However, not very easy for a beginner. Wink

Thank you again
Post 16 Oct 2004, 20:29
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.