Answer to Question #255861 in Assembler for rahi

Question #255861

Write a program using 8086 assembly Language (with proper comments) that accepts a two-digit input from the keyboard, converts it into an equivalent binary number and subtracts this value from every element of an array of length ten bytes. Assume that the array is stored in the memory. Make suitable assumptions, if any.


1
Expert's answer
2021-10-26T17:31:22-0400
DATA SEGMENT
 
array       DB 21, 22, 23, 24, 25, 26, 27, 28, 29, 20
MSG_ENTER    DB 10,13,"Enter TWO number: $"
DATA ENDS

CODE SEGMENT

ASSUME DS:DATA,CS:CODE
START:
    MOV AX,DATA
    MOV DS,AX
    MOV ES,AX    
    
    LEA DX,MSG_ENTER    ; "Enter ..."
    MOV AH,9            ; Display string
    INT 21H

    MOV AH,1            ; Waiting for a key press
    INT 21H
    
    
; AL = ASCII code of key pressed
    SUB AL, 30H            ; AL NUMBER
    XOR DX, DX            ; DX = 0
    mov DL,AL            ; first digit

    MOV AH,1            ; Waiting for a key press
    INT 21H
    
; AL = ASCII code of key pressed
    SUB AL,30H            ; AL NUMBER
    XOR BX, BX
    mov BL,AL            ; second digit

; Calculate tens
     XOR AX,AX            ; AX = 0 before multiplication AX=0
     MOV CL,10
     MOV AL, DL        ; tens
     MUL CL            ; <number of tens>*10
     MOV DX,AX        ; tens    
     ADD DX,BX        ; REZULT
    
    LEA SI,array    ; address of array
    MOV CX, 10        ; counter
L1:
    MOV AL,[SI]        ; AL = array[i]
    SUB AL, DL        ; array[i] - number
    MOV [SI],AL        ; save
    INC SI            ; next address in array
    LOOP L1
    
    mov ah, 4ch        ; exit
    int 21h


CODE ENDS
END START




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS