MASM --- loop basic

  1. Include Irvine32.inc
  2. .data
  3.     MSG0 byte "enter your number: ",0dh,0ah,0
  4.     MSG1 byte "how many digits: ",0dh,0ah,0
  5.     MSG2 byte "enter sth to halt: ",0dh,0ah,0
  6.     number dword 0
  7.     count dword 0
  8. .code
  9.     main proc
  10.     L0:
  11.     mov edx, offset MSG0        ; display string
  12.     call writestring
  13.     call readint
  14.     mov number, eax
  15.     .if (eax <= 0)
  16.     jmp L3
  17.     .endif
  18.     mov ecx, eax        ; do exact same time as number
  19.     mov ebx, 10         ; divide 10 every time
  20.     mov eax, number
  21.     L1:
  22.     .if ( eax > 0 )
  23.         cdq
  24.         mov ebx, 10
  25.         idiv ebx
  26.         inc count
  27.     LOOP L1
  28.     .else
  29.         jmp L2
  30.     .endif
  31.     L2:
  32.     mov edx, offset MSG1
  33.     call writestring
  34.     mov eax, count
  35.     call writedec
  36.     call crlf
  37.     mov count, 0
  38.     jmp L0
  39.     L3:
  40.     mov edx, offset MSG2
  41.     call writestring
  42.     call crlf
  43. exit
  44. main endp
  45. end main


留言

這個網誌中的熱門文章

Codeforces --- string task

Uva 674 ---- coin change

codeforces 271A --- beautiful year