MASM --- loop basic
- Include Irvine32.inc
- .data
- MSG0 byte "enter your number: ",0dh,0ah,0
- MSG1 byte "how many digits: ",0dh,0ah,0
- MSG2 byte "enter sth to halt: ",0dh,0ah,0
- number dword 0
- count dword 0
- .code
- main proc
- L0:
- mov edx, offset MSG0 ; display string
- call writestring
- call readint
- mov number, eax
- .if (eax <= 0)
- jmp L3
- .endif
- mov ecx, eax ; do exact same time as number
- mov ebx, 10 ; divide 10 every time
- mov eax, number
- L1:
- .if ( eax > 0 )
- cdq
- mov ebx, 10
- idiv ebx
- inc count
- LOOP L1
- .else
- jmp L2
- .endif
- L2:
- mov edx, offset MSG1
- call writestring
- mov eax, count
- call writedec
- call crlf
- mov count, 0
- jmp L0
- L3:
- mov edx, offset MSG2
- call writestring
- call crlf
- exit
- main endp
- end main
留言
張貼留言