Code : Tout sélectionner
x = 65
y = 32
tase = 21000
ra = 150 * INT(y / 10) + y
ba = 10 * INT(x / 8)
ma = 2 ^ (7 - (x AND 7))
ad = tase + ra + ba
POKE ad, PEEK(ad) OR ma
Code : Tout sélectionner
ORG 5000h ; Set the start address of the program
START:
; Initialize values
LD A, 65 ; x = 65
LD (x), A ; Store x
LD A, 32 ; y = 32
LD (y), A ; Store y
LD HL, 21000 ; tase = 21000
LD (tase), HL ; Store tase
; Calculate ra = 150 * (y / 10) + y
LD A, (y) ; Load y into A
LD B, 10 ; Set divisor to 10
CALL DIVIDE ; A = y / 10
LD B, A ; Save result in B (y / 10)
LD A, 150 ; Load 150 into A
CALL MULTIPLY ; Multiply 150 * (y / 10)
LD L, A ; Store result in L (150 * (y / 10))
LD A, (y) ; Load y into A
ADD A, L ; ra = 150 * (y / 10) + y
LD (ra), A ; Store ra
; Calculate ba = 10 * (x / 8)
LD A, (x) ; Load x into A
LD B, 8 ; Set divisor to 8
CALL DIVIDE ; A = x / 8
LD B, A ; Save result in B (x / 8)
LD A, 10 ; Load 10 into A
CALL MULTIPLY ; Multiply 10 * (x / 8)
LD (ba), A ; Store ba
; Calculate ma = 2 ^ (7 - (x AND 7))
LD A, (x) ; Load x into A
AND 7 ; x AND 7
LD B, 7
SUB B ; A = 7 - (x AND 7)
LD B, A ; Save result in B
LD A, 1
CALL POWER_OF_TWO ; A = 2 ^ B
LD (ma), A ; Store ma
; Calculate ad = tase + ra + ba
LD HL, (tase) ; Load tase into HL
LD A, (ra) ; Load ra into A
CALL ADD_TO_HL ; HL = HL + ra
LD A, (ba) ; Load ba into A
CALL ADD_TO_HL ; HL = HL + ba
LD (ad), HL ; Store ad
; POKE ad, PEEK(ad) OR ma
LD HL, (ad) ; Load address (ad)
LD A, (HL) ; PEEK(ad)
LD HL, ma ; Load address of ma into HL
LD B, (HL) ; Load ma into B
OR B ; A = A OR B
LD (HL), A ; POKE(ad)
HALT ; End of the program
; Subroutine to divide A by B
DIVIDE:
XOR D ; Clear D
DIV_LOOP:
SUB B ; Subtract B from A
JR C, DIV_END ; If A < B, we're done
INC D ; Increment result
JR DIV_LOOP
DIV_END:
ADD A, B ; Restore A to its value before the last subtraction
LD A, D ; Return quotient in A
RET
; Subroutine to multiply A by B
MULTIPLY:
LD C, A ; Save A in C
LD A, 0 ; Clear A
MULT_LOOP:
ADD A, C ; Add C to A
DEC B ; Decrement B
JR NZ, MULT_LOOP ; If B != 0, continue multiplying
RET
; Subroutine to calculate 2 ^ B
POWER_OF_TWO:
LD A, 1 ; Start with 2^0 = 1
POW_LOOP:
DEC B ; Decrement B
JR Z, POW_END ; If B = 0, we're done
ADD A, A ; Double A (shift left)
JR POW_LOOP ; Repeat until B = 0
POW_END:
RET
; Subroutine to add 8-bit A to 16-bit HL
ADD_TO_HL:
ADD A, L ; Add A to L
LD L, A ; Store result in L
JR NC, NO_CARRY ; If no carry, skip next instruction
INC H ; Increment H if carry
NO_CARRY:
RET
; Variables
x:
dw 0
y:
dw 0
ra:
dw 0
ba:
dw 0
ma:
dw 0
ad:
dw 0