8085 assembly #2: Task #1
7/1/2018
For my first task/learning excercise I wanted to start learning about using memory. To do this I came up with a simple goal: add the numbers together in memory from the memory location 0x00 until the first 0x00 byte is read. While a simple task in a language I am use to like C, I found it difficult to picture how I should control the registers to store and move around the bytes.
The final code to achieve this task (memory filled in manually inside the simulator):
; ADD NUMBERS IN MEMORY 00H -> NEXT 00H BYTE, STORE RESULT IN C JMP START START: LXI H,00H ; HL AS MEMORY POINTER MVI C,00H ; CLEAR C MOV B,C ; CLEAR B NEXT: MOV A,M ; SET ACCUMULATOR TO VALUE AT MEMORY ADDRESS CPI 00H ; COMPARE ACCUMULATOR WITH 00H JZ END ; JUMP IF ZERO INX H ; INCREASE POINTER JMP SAVE ; JUMP TO SAVE SAVE: MOV B,A ; STORE ACCUMULATOR IN B MOV A,C ; MOVE C INTO ACCUMULATOR ADD B ; ADD B MOV C,A ; STORE NEW ADDED VALUED IN B MVI A,00H ; CLEAR ACCUMULATOR MOV B,A ; CLEAR B JMP NEXT ; NEXT BYTE END: HLT ; HALT