Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
1.7 kB
1
Indexable
Never
#START=THERMOMETER.EXE#

TITLE IOANNIS STAMOU

DEDOMENA SEGMENT

    MENU DB "ENTER A DECIMAL NUMBER (0-255):$"

DEDOMENA ENDS

KWDIKAS SEGMENT

ARXH:

    MOV AX, DEDOMENA
    MOV DS, AX

    LEA DX, MENU
    MOV AH, 09h
    INT 21H

    ; Read a three-digit decimal number from the user
    MOV CX, 100 ; Initialize CX with the hundreds place value
    XOR BX, BX  ; Clear BX to store the result
    MOV SI, 3   ; Set SI to the maximum number of digits

READ_DIGIT_LOOP:
    MOV AH, 01h  ; Read a character from input
    INT 21H

    SUB AL, '0'  ; Convert ASCII to integer
    CMP AL, 0    ; Check if it's the end of input
    JE  END_READ_DIGIT_LOOP

    MUL CX       ; Multiply the current digit by its place value
    ADD BX, AX   ; Add the result to the total
    MOV AX, BX   ; Move the result to AX for next iteration
    MOV CX, 10   ; Set CX to the tens place value for the next iteration
    LOOP READ_DIGIT_LOOP

END_READ_DIGIT_LOOP:

    ; Print the entered decimal number
    MOV AX, BX   ; Use AX for binary conversion
    MOV CX, 8    ; Number of bits for an 8-bit binary representation

PRINT_BINARY_LOOP:
    ; Shift the binary representation to the left
    SHL AX, 1

    ; Check the leftmost bit and print '1' or '0'
    JC PRINT_BINARY_PRINT_ONE
    MOV DL, '0'
    JMP PRINT_BINARY_CONTINUE

PRINT_BINARY_PRINT_ONE:
    MOV DL, '1'

PRINT_BINARY_CONTINUE:
    ; Print the binary digit
    MOV AH, 02h
    INT 21H

    ; Repeat for all bits
    LOOP PRINT_BINARY_LOOP

    ; Print a newline
    MOV DL, 10
    MOV AH, 02h
    INT 21H

    ; Terminate the program
    MOV AH, 4Ch
    INT 21H

KWDIKAS ENDS

SOROS SEGMENT STACK

db 265 dup(0)

SOROS ENDS

END ARXH
Leave a Comment