S
S
Sergey_Lomakin2021-03-17 15:48:38
assembler
Sergey_Lomakin, 2021-03-17 15:48:38

How to create a procedure that displays a character code in HEX format?

I can’t create a procedure that outputs a character code in HEX format, I have already searched through many forums and nothing, what am I doing wrong?

ideal
  model	small
  stack	256
  include	"primer1.uno"
  dataseg
simvol	db	?
  codeseg
  extrn	write_2:proc, write_10:proc, write_16:proc	
start:
  mov	ax,@data
  mov	ds,ax
  mov	ah,1
  int	21h
  mov	[simvol],al		
  probel				
  mov	bl,[simvol]
  call	write_2			
  probel
  mov	dh,0
  mov	dl,[simvol]
  call	write_10		
  probel
  mov	dh,0
  mov	dl,[simvol]
  call	write_16		
  mov	ax,4c00h
  int	21h
  end	start

procedure file PROC4.ASM
push	dx
  push	si
  mov	ax,dx
  mov	si,10	
  mov	cx,0	
non_zero:
  mov	dx,0
  div	si
  push	dx	
  inc 	cx
  cmp	ax,0
  jne	non_zero
metka1:
  pop	dx
  call	wr_cifra
  loop	metka1
  pop	si
  pop	dx
  pop	cx
  pop	ax
  ret
  endp

  proc	wr_cifra
  add	dl,30h
  mov	ah,2
  int	21h
  ret
  endp

  proc	write_16
  push	ax
  push	cx
  push	dx
  push	bx
  mov	ax,dx
  mov	si,16
  mov	cx,0
non_zero_w16:
  mov	dx,0
  div	si
  push	dx
  inc	cx
  cmp	ax,0
  jne	non_zero_w16
metka2:
  pop	dx
  call	wr_cifra
  loop	metka2
  pop	si
  pop	dx
  pop	cx
  pop	ax
  ret
  endp
  end

macro file PRIMER1.UNO
macro	probel
  push	ax
  push	dx
  mov	ah,2
  mov	dl," "
  int	21h
  pop	dx
  pop	ax
  endm

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
pfemidi, 2021-03-17
@Sergey_Lomakin

A beautiful hack for displaying AL in hexadecimal form, which I spied back in 1989 in SYMDEB.EXE and liked it so much at one time that I remembered it for the rest of my life. Here is a slightly modified version from the original from SYMDEB.EXE (it used all sorts of additional checks that I threw out here). Please note - not a single comparison, not a single conditional transition!

AL_to_HEX       proc near
        push    ax
        shr     al,4
        call    @@outNibble
        pop     ax
@@outNubble:
        and     al,0fh
        add     al,90h
        daa
        adc     al,40h
        daa
        mov     ah,0eh
        int     10h
        ret
AL_TO_HEX       endp

F
freeExec, 2021-03-17
@freeExec

what am i doing wrong

Do not debug your code. No one will do it for you for free, especially in asma.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question