summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TASK4.asm29
1 files changed, 29 insertions, 0 deletions
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