English

A Hex number is stored at location 2100H. Write an Assembly Language Program to interchange its digit, the new number is to be stored in 2105H. Add original number with new number and store the result - Computer Science 2

Advertisements
Advertisements

Question

A Hex number is stored at location 2100H. Write an Assembly Language Program to interchange its digit, the new number is to be stored in 2105H. Add original number with new number and store the result at location 2105H.

Code Writing
Advertisements

Solution

        LDA 2100H        ; A = original number
        MOV B, A         ; Save original in B

        ; ---- Swap digits (nibbles) ----
        MOV A, B
        ANI 0FH          ; Get lower nibble
        RLC
        RLC
        RLC
        RLC              ; Shift it to upper nibble position
        MOV D, A         ; D = (lower nibble << 4)

        MOV A, B
        ANI F0H          ; Get upper nibble
        RRC
        RRC
        RRC
        RRC              ; Shift it to lower nibble position
        ORA D            ; Combine -> swapped number in A

        STA 2105H        ; Store swapped number at 2105H

        ; ---- Add original + swapped ----
        ADD B            ; A = swapped + original
        STA 2105H        ; Store sum at 2105H (overwrites swapped)

        HLT
shaalaa.com
  Is there an error in this question or solution?
2021-2022 (March) Set 1

APPEARS IN

Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×