From c0b13d7fc1eeef8398f4ef4dad2b87ba34a392f4 Mon Sep 17 00:00:00 2001 From: daniel-Jones Date: Sat, 20 Jan 2018 15:44:42 +1030 Subject: task 4, multiplication using sub routine --- TASK4.asm | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 TASK4.asm diff --git a/TASK4.asm b/TASK4.asm new file mode 100644 index 0000000..cd32da8 --- /dev/null +++ b/TASK4.asm @@ -0,0 +1,29 @@ +; 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 \ No newline at end of file -- cgit v1.2.3