-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
09140d1
commit 9d40d59
Showing
11 changed files
with
505 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
|
||
;org 0x0100 | ||
;mov ax,0x0100 | ||
;call display_number | ||
;int 0x20 | ||
; -------------- | ||
int 0x20 | ||
; Display letter contained in AL (ASCII) | ||
display_letter: | ||
push ax | ||
push bx | ||
push cx | ||
push dx | ||
push si | ||
push di | ||
mov ah,0x0e ; Load AH with code for terminal output | ||
mov bx,0x000f ; Load BH page zero adn BL color (graphic mode) | ||
int 0x10 ; Call the BIOS for displaying one letter | ||
pop di | ||
pop si | ||
pop dx | ||
pop cx | ||
pop bx | ||
pop ax | ||
ret ; Returns to caller | ||
; Read keyboard into AL (ASCII) | ||
read_keyboard: | ||
push bx | ||
push cx | ||
push dx | ||
push si | ||
push di | ||
mov ah,0x00 ; Load AH with code for keyboard read | ||
int 0x16 ; Call the BIOS for reading keyboard | ||
pop di | ||
pop si | ||
pop dx | ||
pop cx | ||
pop bx | ||
ret ; Returns to caller | ||
|
||
; | ||
; Display the value of AX as a decimal number | ||
; | ||
display_number: | ||
mov dx,0 | ||
mov cx,10 | ||
div cx ; AX = DX: AX / CX | ||
push dx | ||
cmp ax,0 ; if ax is zero | ||
je display_number_1 ; jump | ||
call display_number ; else calls itself again | ||
display_number_1: | ||
pop ax | ||
add al,'0' ; convert remainder to ascii digit | ||
call display_letter ; display on the screen | ||
ret | ||
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
|
||
; | ||
; Sieve of Eratosthenes | ||
; | ||
org 0x0100 | ||
table: equ 0x8000 | ||
table_size: equ 1000 | ||
|
||
start: | ||
mov bx,table | ||
mov cx,table_size | ||
mov al,0 | ||
p1: | ||
mov [bx],al ; Write AL into the address pointed by BX | ||
inc bx ; increase bx | ||
loop p1 ; Decrease CX, jump if non zero | ||
mov ax,2 ; start at number 2 | ||
p2: mov bx,table; BX = table address | ||
add bx,ax ; BX=BX+AX | ||
cmp byte [bx],0 ; is it prime? | ||
jne p3 | ||
push ax | ||
call display_number | ||
mov al,0x2c ; Comma | ||
call display_letter | ||
pop ax | ||
mov bx,table | ||
add bx,ax | ||
p4: add bx,ax | ||
cmp bx,table+table_size | ||
jnc p3 | ||
mov byte [bx],1 | ||
jmp p4 | ||
p3: inc ax | ||
cmp ax,table_size | ||
jne p2 | ||
; -------------- | ||
int 0x20 | ||
; Display letter contained in AL (ASCII) | ||
display_letter: | ||
push ax | ||
push bx | ||
push cx | ||
push dx | ||
push si | ||
push di | ||
mov ah,0x0e ; Load AH with code for terminal output | ||
mov bx,0x000f ; Load BH page zero adn BL color (graphic mode) | ||
int 0x10 ; Call the BIOS for displaying one letter | ||
pop di | ||
pop si | ||
pop dx | ||
pop cx | ||
pop bx | ||
pop ax | ||
ret ; Returns to caller | ||
; Read keyboard into AL (ASCII) | ||
read_keyboard: | ||
push bx | ||
push cx | ||
push dx | ||
push si | ||
push di | ||
mov ah,0x00 ; Load AH with code for keyboard read | ||
int 0x16 ; Call the BIOS for reading keyboard | ||
pop di | ||
pop si | ||
pop dx | ||
pop cx | ||
pop bx | ||
ret ; Returns to caller | ||
|
||
|
||
; | ||
; Display the value of AX as a decimal number | ||
; | ||
display_number: | ||
mov dx,0 | ||
mov cx,10 | ||
div cx ; AX = DX: AX / CX | ||
push dx | ||
cmp ax,0 ; if ax is zero | ||
je display_number_1 ; jump | ||
call display_number ; else calls itself again | ||
display_number_1: | ||
pop ax | ||
add al,'0' ; convert remainder to ascii digit | ||
call display_letter ; display on the screen | ||
ret | ||
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
|
||
; | ||
; Sieve of Eratosthenes | ||
; | ||
org 0x0100 | ||
table: equ 0x8000 | ||
table_size: equ 1000 | ||
|
||
start: | ||
mov bx,table | ||
mov cx,table_size | ||
mov al,0 | ||
p1: | ||
mov [bx],al ; Write AL into the address pointed by BX | ||
inc bx ; increase bx | ||
loop p1 ; Decrease CX, jump if non zero | ||
mov ax,2 ; start at number 2 | ||
p2: mov bx,table; BX = table address | ||
add bx,ax ; BX=BX+AX | ||
cmp byte [bx],0 ; is it prime? | ||
jne p3 | ||
push ax | ||
call display_number | ||
mov al,0x0d ; Comma | ||
call display_letter | ||
mov al,0x0a ; Comma | ||
call display_letter | ||
pop ax | ||
mov bx,table | ||
add bx,ax | ||
p4: add bx,ax | ||
cmp bx,table+table_size | ||
jnc p3 | ||
mov byte [bx],1 | ||
jmp p4 | ||
p3: inc ax | ||
cmp ax,table_size | ||
jne p2 | ||
; -------------- | ||
int 0x20 | ||
; Display letter contained in AL (ASCII) | ||
display_letter: | ||
push ax | ||
push bx | ||
push cx | ||
push dx | ||
push si | ||
push di | ||
mov ah,0x0e ; Load AH with code for terminal output | ||
mov bx,0x000f ; Load BH page zero adn BL color (graphic mode) | ||
int 0x10 ; Call the BIOS for displaying one letter | ||
pop di | ||
pop si | ||
pop dx | ||
pop cx | ||
pop bx | ||
pop ax | ||
ret ; Returns to caller | ||
; Read keyboard into AL (ASCII) | ||
read_keyboard: | ||
push bx | ||
push cx | ||
push dx | ||
push si | ||
push di | ||
mov ah,0x00 ; Load AH with code for keyboard read | ||
int 0x16 ; Call the BIOS for reading keyboard | ||
pop di | ||
pop si | ||
pop dx | ||
pop cx | ||
pop bx | ||
ret ; Returns to caller | ||
|
||
|
||
; | ||
; Display the value of AX as a decimal number | ||
; | ||
display_number: | ||
mov dx,0 | ||
mov cx,10 | ||
div cx ; AX = DX: AX / CX | ||
push dx | ||
cmp ax,0 ; if ax is zero | ||
je display_number_1 ; jump | ||
call display_number ; else calls itself again | ||
display_number_1: | ||
pop ax | ||
add al,'0' ; convert remainder to ascii digit | ||
call display_letter ; display on the screen | ||
ret | ||
Binary file not shown.
Empty file.
Empty file.
Oops, something went wrong.