I am looking for guidance on how to print the hex value of a number entered from the keyboard. Enter a value when prompted, for comment consistency enter the number 4. I want that number 4 to display the cooresponding value in hex. IE, enter 4 on keyboard, print 34 on the screen. The value I want to print is located in AL, but I can only display the enter value of 4. How do I print the value in AL? Thanks for any help.
[code]
ORG 100h
Set:
mov sp,8000h ;set stack
mov ax,0002h ;select mode 02h display monitor
int 10h ;BIOS sets mode via int 10h
mov ah,01h ;set half size cursor
mov cx,0006h
int 10h ;BIOS sets half size cursor
poll:
mov ah,02h ;position cursor on page 0
mov bh,00h ;cursor on page 0
mov dx,0c25h ;position on row 12, column 37
int 10h ;cursor positioned
mov ah,00h ;get the key ASCII code in AL
int 16h ;ENTER A '4' FOR TESTING PURPOSES
mov dl,al ;store for later use
cmp ah,01h ;stop if Esc key hit
jne screen ;if not then display key
mov ax,4c00h ;if yes back to DOS
int 21h
screen:
mov ah,09h ;display character function
mov bh,00h ;page 0
mov bl,1fh ;white character, blue background
mov cx, 0001h ;one character
;HOW DO I DISPLAY '34' THE VALUE THAT'S IN AL?
int 10h ;display it
jmp poll ;next character
[/code]
Comments
: entered from the keyboard. Enter a value when prompted, for comment
: consistency enter the number 4. I want that number 4 to display the
: cooresponding value in hex. IE, enter 4 on keyboard, print 34 on
: the screen. The value I want to print is located in AL, but I can
: only display the enter value of 4. How do I print the value in AL?
: Thanks for any help.
:
: [code]:
: ORG 100h
:
: Set:
: mov sp,8000h ;set stack
: mov ax,0002h ;select mode 02h display monitor
: int 10h ;BIOS sets mode via int 10h
: mov ah,01h ;set half size cursor
: mov cx,0006h
: int 10h ;BIOS sets half size cursor
:
: poll:
: mov ah,02h ;position cursor on page 0
: mov bh,00h ;cursor on page 0
: mov dx,0c25h ;position on row 12, column 37
: int 10h ;cursor positioned
: mov ah,00h ;get the key ASCII code in AL
:
: int 16h ;ENTER A '4' FOR TESTING PURPOSES
:
: mov dl,al ;store for later use
: cmp ah,01h ;stop if Esc key hit
: jne screen ;if not then display key
: mov ax,4c00h ;if yes back to DOS
: int 21h
:
: screen:
: mov ah,09h ;display character function
: mov bh,00h ;page 0
: mov bl,1fh ;white character, blue background
: mov cx, 0001h ;one character
:
: ;HOW DO I DISPLAY '34' THE VALUE THAT'S IN AL?
:
: int 10h ;display it
: jmp poll ;next character
: [/code]:
Here's some C++ code that does what you want:
[code]
char* arr = "0123456789ABCDEF";
out << arr[al&0xf];
out << arr[al&0xff>>4];
[/code]
Use the same principle.
: trouble with whereas I have some experience w/ C/C++ as well. I am
: specifically looking for instruction help on how to display the
: value of AL which is a hex value using the function 01h method.
: Please see initial post for description of what I am looking for -
: thanks for the effort!
:
Yes, and I described how to do it in a psuedo way.
You'll need to output two chars, as becouse you want to do that. And you get the different chars by using the technique described above.
al&0xf is simply and al,0xf in asm.
and al >> 4, is simply shr ax,4
and 'indexing' is done by adding, like this:
hexChars: db "0123456789ABCDEF"
mov [hexChars+al]
All simple things in C is simple in assembly (this isn't really true, but almost).
Now I've written you almost everything.
And I did make a mistake in my previus post, the second output line should be:
[code]
out << arr[al>>4];
[/code]
: entered from the keyboard. Enter a value when prompted, for comment
: consistency enter the number 4. I want that number 4 to display the
: cooresponding value in hex. IE, enter 4 on keyboard, print 34 on
: the screen. The value I want to print is located in AL, but I can
: only display the enter value of 4. How do I print the value in AL?
: Thanks for any help.
:
: [code]:
: ORG 100h
:
: Set:
: mov sp,8000h ;set stack
: mov ax,0002h ;select mode 02h display monitor
: int 10h ;BIOS sets mode via int 10h
: mov ah,01h ;set half size cursor
: mov cx,0006h
: int 10h ;BIOS sets half size cursor
:
: poll:
: mov ah,02h ;position cursor on page 0
: mov bh,00h ;cursor on page 0
: mov dx,0c25h ;position on row 12, column 37
: int 10h ;cursor positioned
: mov ah,00h ;get the key ASCII code in AL
:
: int 16h ;ENTER A '4' FOR TESTING PURPOSES
:
: mov dl,al ;store for later use
: cmp ah,01h ;stop if Esc key hit
: jne screen ;if not then display key
: mov ax,4c00h ;if yes back to DOS
: int 21h
:
: screen:
: mov ah,09h ;display character function
: mov bh,00h ;page 0
: mov bl,1fh ;white character, blue background
: mov cx, 0001h ;one character
:
: ;HOW DO I DISPLAY '34' THE VALUE THAT'S IN AL?
:
: int 10h ;display it
: jmp poll ;next character
: [/code]:
My code is not perfect but you get the idea
Set:
push cs
pop ds
mov sp,8000h ;set stack
mov ax,0002h ;select mode 02h display monitor
int 10h ;BIOS sets mode via int 10h
mov ah,01h ;set half size cursor
mov cx,0006h
int 10h ;BIOS sets half size cursor
poll:
mov dx,0c25h ;position on row 12, column 37
call set_cursor
mov ah,00h ;get the key ASCII code in AL
int 16h ;ENTER A '4' FOR TESTING PURPOSES
mov dl,al ;store for later use
cmp ah,01h ;stop if Esc key hit
jne screen ;if not then display key
mov ax,4c00h ;if yes back to DOS
int 21h
screen:
mov bx,offset cs:charBuff
xor ah,ah
call Hexasc
mov si,offset cs:charBuff
mov dx,0c25h ;position on row 12, column 37
nxtchar:
call set_cursor
push dx
mov ah,09h ;display character function
mov bh,00h ;page 0
mov bl,1fh ;white character, blue background
mov cx, 0001h ;one character
lodsb
int 10h
pop dx
inc dl
or al,al
jnz nxtchar
jmp poll ;next character
Hexasc proc near
;call with:
; ax=hex value
; ds:bx = address of buffer
push cx
push dx
mov dx,4
Hexasc1:
mov cx,4
rol ax,cl
mov cx,ax
and cx,0fh
add cx,'0'
cmp cx,'9'
jbe hexasc2
add cx,'A'-'9'-1
Hexasc2:
mov [bx],cl
inc bx
dec dx
jnz Hexasc1
pop dx
pop cx
ret
Hexasc endp
set_cursor proc near
mov ah,02h ;position cursor on page 0
mov bh,00h ;cursor on page 0
int 10h ;cursor positioned
ret
set_cursor endp
charBuff db 5 dup(0)