Skip to content

Instantly share code, notes, and snippets.

@frgtn
Created October 27, 2010 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frgtn/649519 to your computer and use it in GitHub Desktop.
Save frgtn/649519 to your computer and use it in GitHub Desktop.
Radavičiaus asm kontrolinis
;
; Salyga:
; Parasyti programa, kuri kiekviena ivestoje tekstineje eiluteje esanti desimtaini skaiciu pakeicia jo dalybos is 3 liekana ir
; isveda gauta eilute i ekrana. Maksimalus leistinas eilutes ilgis - 255 simboliai.
.model small
.stack 100h
buff_size equ 255
.data
enter_data db "Enter a line of text:", 10, 13, '$'
newline db 10, 13, '$'
buffsize1 db buff_size
bytes_read db ?
buff1 db buff_size dup (?)
buff2 db buff_size+1 dup (?)
.code
start:
mov ax, @data
mov ds, ax
mov dx, offset enter_data
mov ah, 09h
int 21h
mov dx, offset buffsize1
mov ah, 0Ah
int 21h
mov ah, 09h
mov dx, offset newline
int 21h
xor dx, dx
mov si, offset buff1
mov cl, byte ptr bytes_read
cmp cl, 0
je exit
mov di, offset buff2
main_loop:
cmp byte ptr [ds:si], '0'
jb non_digit
cmp byte ptr [ds:si], '9'
ja non_digit
digit:
xor dx, dx
mov dl, [ds:si]
sub dl, '0'
add ax, dx
mov dh, 1
jmp continue
non_digit:
cmp dh, 1
jne copy
call print_remainder
xor ax, ax
xor dx, dx
copy:
mov ch, [ds:si]
mov [ds:di], ch
inc di
continue:
inc si
dec cl
cmp cl, 0
jne main_loop
cmp dh, 1
jne print_line
call print_remainder
print_line:
mov byte ptr [ds:di], '$'
mov dx, offset buff2
mov ah, 09h
int 21h
exit:
mov ax, 4c00h
int 21h
proc print_remainder
push cx
push dx
xor dx, dx
mov cx, 3
div cx
add dl, '0'
mov [ds:di], dl
inc di
pop dx
pop cx
ret
endp print_remainder
end start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment