2010-06-29 66 views
0

這是/從屬於從NAND到俄羅斯方塊四,和希伯來大學的OCW(我不參加,我只是在踢球)。它所做的是,當任何按鍵被按下時,它會使每個像素變黑。當鑰匙被釋放時,「屏幕」被清除。需要幫助在哈克ASM ROM中的groking代碼片段

這裏的ROM本身:

// Fill.asm 

// Fills the 'screen' with black, 
// one pixel at a time, when any 
// key is pressed and held. 

// When the key is released, the 
// screen should clear. 


// i = 0 

@i 
M=0 

(LOOP) 
// color = 0xFFFF (black) = !0 
D=0 
D=!D 
@color 
M=D 

@KBD  // Location of keypress code 
    // is RAM[24576] = RAM(0x600) 
D=M   // D != 0 if a key is pressed 

@SKIP_WHITE 
D;JNE 


// if (key == 0) 
// { 
// color = 0 (white) 

@color 
M=0 

// } 


(SKIP_WHITE) 
// Ensure that the offset is 
// within the screen's 8K 
// memory area 
     @i 
M=M+1 
@8191 
D=A 
@i 
M=M&D 


@i 
D=M 
@SCREEN 
D=D+A  
@target 
M=D 
@color 
D=M 
@target 
A=M  // GOTO Pixel specified by target 
M=D 


@LOOP // infinite loop, baby 
0;JMP 

我真的很好奇什麼是第二個代碼末塊,一個關於屏幕的內存區域的偏移。我寫了其他所有內容,但是直到有人向我提供了該代碼塊之後,該程序才運行。任何人都可以向我解釋它在做什麼?

回答

1

我想通了!

8191是虛擬屏幕8K內存區域內的最大位數。通過將迭代器與最大值進行AND運算,我們確保我們不會嘗試寫入屏幕外的像素。