Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; given a string over std inpput calculate sum of multiplies of 5 smaller or equal of it
- ; eg: 34 gives => sum = 30 + 25 + 20 + 15 + 10 + 5 = 105
- .data
- input DB ?
- sum DB ?
- .code
- org 100h
- start:
- mov ah, 01h
- int 21h
- mov input, ah
- mov si, input ;si points to string
- loopStringToInt:
- lodsb ;load the first byte pointed by ESI in al
- cmp al,'0' ;check if it's an ascii number [0-9]
- jb noascii ;not ascii, exit
- cmp al,'9' ;check the if it's an ascii number [0-9]
- ja noascii ;not ascii, exit
- sub al,30h ;ascii '0' = 30h, ascii '1' = 31h ...etc.
- cbw ;byte to word
- push ax
- mov ax,bx ;bx will contain '12345' in hexadecimal
- mov cx,10
- mul cx ;AX=AX*10
- mov bx,ax
- pop ax
- add bx,ax
- jmp loopStringToInt ;continue until ESI points to a non-ascii [0-9] character
- noascii:
- ret ;bx contains integer now
- loopFives:
- mov cx, 5 ; seed value = 5
- cmp bx, cx ; has cx reached bx yet?
- jna printsum ;if so print and pass operation back to OS
- add sum, cx ; if not, increase sum
- add cx, 5 ; get next multiply of 5
- jmp loopFives ;; continue loop
- printsum:
- mov dl, sum
- mov ah, 02h
- int 21h
- int 27h
- end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement