Skip to content

Instantly share code, notes, and snippets.

@frgtn frgtn/gist:649519

Created Oct 27, 2010
What would you like to do?
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
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 (?)
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
cmp byte ptr [ds:si], '0'
jb non_digit
cmp byte ptr [ds:si], '9'
ja non_digit
xor dx, dx
mov dl, [ds:si]
sub dl, '0'
add ax, dx
mov dh, 1
jmp continue
cmp dh, 1
jne copy
call print_remainder
xor ax, ax
xor dx, dx
mov ch, [ds:si]
mov [ds:di], ch
inc di
inc si
dec cl
cmp cl, 0
jne main_loop
cmp dh, 1
jne print_line
call print_remainder
mov byte ptr [ds:di], '$'
mov dx, offset buff2
mov ah, 09h
int 21h
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
endp print_remainder
end start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.