Somma e sottrazione di locazioni di memoria usando l’indirizzamento indiretto

Add and subtract memory locations using indirect addressing

;Add and substract mamory locations using indirect addressing

VAL1 EQU 37H      ;DECIMAL VALUE = 55

VAL2 EQU 2CH      ;DECIMAL VALUE = 44

LOC1 EQU 0C350H

         ORG 0000h

        JP   0100h

        ORG 0100h

PROG :     LD HL,LOC1      ;initialize the register HL at the value LOC1

           LD A,VAL1       ;load the value VAL1 in the accumulator A

            LD   (HL),A      ;load the value of A in the address of the register HL (0c350h)

           INC HL          ;increment HL (0c351h)

           LD   (HL),A      ;load the value of A in the address of the register HL (0c351h)

           dec hl           ;0c350h

           ADD A,(HL)      ;add the value in the register HL (0c350h) the value that is in the accumulator A(the value that is in 0c351h)

                          ; and put the result in A

           INC HL          ;increment HL(0c351h)

           inc hl          ;increment HL(0c352h)

           LD (hl),VAL2    ;load the value VAL2 in the register Hl

           SUB (HL)        ;substract Val2 to the value that is in A

           LD (HL),A       ; load the result of the substraction in the register Hl(0c352h)

HALT

NOTE: Changing the values of the first two operands and setting them to 140 (8CH)   makes a different result in their addiction, this will be 118 (hexadecimal) a 9 bit number that will force the accumulator   A to borrow a 1 to carry flag, the code with the comments has been pasted below:

                          ….

           dec hl          ;0c350h

           ADD A,(HL)      ;add the value in the register HL (0c350h) the value that is in the accumulator A(the value that is in 0c351h)

                          ;and put the result in A, the result of the addiction between 140 and 140 (decimal) is 118 (hexadecimal)

                          ;but 118 is a 9 bit number, so in A there will be the less significants 8 bits, and the nineth bit is borrowed

                          ;to the carry flag  

           INC HL          ;increment HL(0c351h)

Lascia un commento