can someone explain this every statement?

    • can someone explain this every statement?

      Proc InputProc

      mov ah, 01h
      int 21h
      cmp al, 0dh
      je FirstTest

      mov ah, 0
      sub al, 30h
      push ax
      mov ax, 10d
      mul bx
      pop bx
      add bx, ax
      jmp inputProc

      call FirstTest

      Proc FirstTest

      mov ax, bx
      push ax
      mov bx, 004h
      div bx
      cmp dx, 0
      je SecondTest
      jmp leapFalse


      Proc SecondTest
      pop ax
      push ax
      mov bx, 0100h
      div bx
      cmp dx, 0
      je ThirdTest
      jmp leapTrue

      Proc ThirdTest

      pop ax
      mov bx, 0400h
      div bx
      cmp dx, 0
      je leapTrue
      jmp leapFalse

    • I disagree that the the logic is difficult to explain in the above example, yet I worry that my response would be in vain. Without asking specific questions I fear that any explanation will not be helpful as you may not have the background necessary to understand the explanation. The example itself is fairly straightforward, but some assumptions must be made due to missing information such as calling conventions.

      I agree with the suggestion of reading ASM tutorials and encourage you to ask specific questions of a narrow scope.
    • The program is buggy.
      And I agree that you need to read a tutorial book.

      Source Code

      1. ; input a number from the console
      2. ; store the number in BX
      3. ; then test whether it is a leap year
      4. Proc InputProc
      5. mov ah, 01h ; dos API, get character
      6. int 21h
      7. cmp al, 0dh ; end of line ? (enter pressed)
      8. je FirstTest ; yes, so test whether it is a leap year
      9. mov ah, 0
      10. sub al, 30h ; convert ASCII into number
      11. push ax ; add the newly read digit(ax) to year (bx)
      12. mov ax, 10d ; formula is :
      13. mul bx ; bx=bx*10+ax
      14. pop bx ; There is a potential bug : bx was not initialize
      15. add bx, ax ; at the beginning of InputProc
      16. jmp inputProc ; read next digit into ax
      17. call FirstTest ; this line is impossible to reach, may remove it
      18. ENDP
      19. ; first test, if bx is NOT divisible by 4,
      20. ; then it is NOT a leap year
      21. Proc FirstTest
      22. mov ax, bx
      23. push ax
      24. mov bx, 004h
      25. div bx
      26. cmp dx, 0
      27. je SecondTest ; divisible by 4, still need to do second test
      28. jmp leapFalse
      29. RET
      30. EndP
      31. ; second test, if BX is divisible by 4
      32. ; but NOT divisible by 100,
      33. ; then it MUST be a leap year
      34. Proc SecondTest
      35. pop ax
      36. push ax
      37. mov bx, 0100h ; a bug here, 0100h is HEX, should use 100
      38. div bx
      39. cmp dx, 0
      40. je ThirdTest ; if divisible by 100, need further testing
      41. jmp leapTrue
      42. EndP
      43. ; third test, if BX is divisible by 400
      44. ; then it is a leap year
      45. Proc ThirdTest
      46. pop ax
      47. mov bx, 0400h ; a bug here, should use 400, not 0400h
      48. div bx
      49. cmp dx, 0
      50. je leapTrue
      51. jmp leapFalse
      52. EndP
      Display All
      API belongs to public. Knowledge belongs to yourself