K
K
Kezzya2021-10-31 18:49:06
assembler
Kezzya, 2021-10-31 18:49:06

Can you explain parts of the code in assembler?

.model tiny
.code
.486
org 100h
.startup
  a:xor   ax,ax
    int   16h
    and   ax,255
    imul  dx,ax,5
    add   dx,offset roman-'1'*5
    mov   ah,9
    int   21h
  jmp a
roman db 'I$$$$II$$$III$$IV$$$V$$$$VI$$$VII$$VIII$IX$'  
end


How does this code convert Arabic numerals to Roman numerals?
int16h - writes what we enter from the keyboard, for example, the number 5, but there is no function here, I don’t understand in which register the number is written, purely from my assumption in the register ah
and ax, 255 - as I understand it, it is translated into binary code and beaten are compared, so there will be 5 in ah? and it is not clear why they did this at all
imul dx,ax,5 - 5 is multiplied by 5 and written to dx, dx = 25, it is not clear why
add dx,offset roman-'1'*5 - add a line to 25??? and what happens
next is just a conclusion, as I understand it

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
User700, 2021-10-31
@Kezzya

Called int 16h with function code 0 (xor ax,ax is ax:=0). This is reading a character from the keyboard. Further, only the low byte is left in ax (aka AL, AH is cleared =0) (and ax, 0000000011111111b (=255)). In AL there will be a character code. It is multiplied by 5 and added to the offset at the beginning of the line, minus the offset for pressing 1 (i.e. if 1 is pressed, the initial offset of this line will be obtained, if 2 is supposed to be the initial offset plus 5, etc.). Taking into account that the line is connected 5 lines of 5 characters each, and the '$' symbol signals the end of the output (for function 09 of the DOS service), the address of the line with the Roman designation of the entered digit will be obtained (by idea). Further it is deduced by function 9 of interruption int 21h.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question