Analisi di un semplice programma aritmetico Assembly

;—————————————————————–

; Analysis and tracing of a simple arithmetic program

;—————————————————————–

;;

        ORG 0000h

        JP   3000h

        ORG 3000h         ;the program strats his first isctruction at 3000h address

;

START :   LD   HL,1200h      ;load the value 1200h in the HL register

        LD   BC,0100h      ;load the vlaue 0100h in the BC register

        LD   DE,0000h      ;load the value 0000h in the DE register

;

LOOP :    LD   A,E     ;he re starts a loop: load the value that is in the register E in A

        ADD A,(HL) ;add the value FFh that is in the address of HL (1200h) and the value that is                                                                                                                         

        in A

        JP   NC,NO_CARRY   ; conditional jump: if no carry jump to NO_CARRY else increment the       register D

        INC D                     

;

NO_CARRY :LD E,A           ;load the value that is in A (the result of addiction)in the register E

        INC HL            ;incement HL register

        DEC BC            ;decrement BC register

        LD   A,B            ; load the value that is in B in A

        OR   C             ; this instruction makes the logical OR operation between each bit of the value in A and C

        JP   NZ,LOOP       ;if the result is not zero, go to LOOP ***NOTE

        LD   HL,8000h      ;else load the value 8000h in the HL register

        LD   (HL),E        ;load the value of E in the address of HL register

        INC HL            ;increment HL register

        LD   (HL),D        ;load the value of D in the address , now increased, in the address of HL

        HALT           

***NOTE: this Loop will go on for 256d times, then when both the value in A and in C will be 00h the program will execute   the next instructions till the Halt

Lascia un commento