8085 assembly #5: Task #4
17/1/2018
Task 4 is a subroutine implementation of multiplication. In addition of using a subroutine the program uses a list which is a defined portion of memory you can address. The subrotuine requires three bytes of memory - a byte for the multiplicand, multiplier and a storage byte for the result. The comments as always are very helpful if you're trying to understand it.
; CALLING A ROUTINE AND PREPARE A MEMORY ADDRESS ; ROUTINE WILL REQUIRE 3 BYTES FIRST NUMBER -> SECOND NUMBER -> RESULT STORAGE ; ROUTINE WILL MULTIPLY M WITH M+1 AND STORE RESULT IN M+2 JMP START ; DEFINE A LIST TO STORE OUR REQUIRED BYTES ; DB = DEFINE BYTE ; DS = DEFINE STORAGE. OPERAND IS NUMBER OF BYTES MULTI1: DB 05H ; MULTIPLICAND DB 03H ; MULTIPLIER DS 01H ; RESERVES "ONE BYTE OF STORAGE START: LXI H,MULTI1 ; LOAD HL AS POINTER TO MULTI1 LIST MEMORY ADDRESS MVI A,0 ; CLEAR A MOV D,M ; STORE MULTIPLICAND IN D INX H ; INCREASE MEMORY POINTER TO GET MULTIPLIER MOV E,M ; STORE MULTIPLIER IN E MVI C,00H ; COUNTER SET TO 0 CALL MULT ; CALL MULTIPLY FUNCTION INX H ; INCREASE MEMORY POINTER TO RESULT STORAGE MOV M,A ; STORE RESULT HLT ; HALT MULT: MOV B,A ; STORE A MOV A,C ; MOVE COUNTER INTO A CMP E ; COMPARE MULTIPLIER TO COUNTER MOV A,B ; MOVE B STORAGE BACK INTO A RZ ; RETURN IF ZERO FLAG SET (COUNTER == MULTIPLIER) INR C ; INCREASE COUNTER ADD D ; ADD MULTIPLICAND TO A JMP MULT ; JUMP TO MULT