100 doors/8086 Assembly: Difference between revisions

m
Fixed syntax highlighting.
(moved from 100 doors)
 
m (Fixed syntax highlighting.)
 
(One intermediate revision by one other user not shown)
Line 4:
 
This example is 51 bytes big when assembled, it is fully commented, and it isn't optimized. The doors are represented in RAM by 100 bytes, which can have value 00 if the door is closed, FF is the door is opened. This example is designed to be run on any 8086 based computer, and it requires to be loaded in RAM, with 100 bytes available to it after the code, to be used for door storing. See the program comments for further explaining.
<langsyntaxhighlight lang="asm">; ** Initialize
; Open all the doors.
; The first pass in toggling the doors starts
Line 88:
doors: ; Pointer to the end of the program,
;where the RAM space is free to keep the
;100 doors bytes.</langsyntaxhighlight>
'''optimized'''
 
This example is 42 bytes big when assembled, it is fully commented, and it is optimized. See the unoptimized program's notes and the program comments for further explaining.
<langsyntaxhighlight lang="asm">; ** Initialize
; Close all the doors.
 
Line 111:
;two doors and reducing the time needed
;to do the task.
and cl,cl ; Set the flags according to cl.
 
initloop:
jz dodoor ; If the counter is zero continue
;to the main loop.
mov [bx],ax ; Close two doors (write a 0000 word).
inc bx ; Increment the pointer.
inc bx
dec cl ; Decrement the counter.
jmpjnz initloop ; Loop or else fall through.
 
; ** Main
Line 170 ⟶ 167:
doors: ; Pointer to the end of the program,
;where the RAM space is free to keep the
;100 doors bytes.</langsyntaxhighlight>
The program could be written scrapping the init code and adding the initialized bytes directly in the source code, after the "doors" pointer, but the initialization code takes less space than 100 $FF bytes.
9,482

edits