Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 13th, 2013, 12:21 PM   #1
kayxxx
Newbie
 
Join Date: Feb 2013
Posts: 6
Rep Power: 0 kayxxx is on a distinguished road
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
ENDP

Proc FirstTest

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

RET
EndP

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

Proc ThirdTest

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

EndP
kayxxx is offline   Reply With Quote
Old Jun 13th, 2013, 2:05 PM   #2
Ancient Dragon
Achieved Level 70

 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 4,345
Rep Power: 10 Ancient Dragon will become famous soon enoughAncient Dragon will become famous soon enough
Re: can someone explain this every statement?

I think you need to read an assembly language tutorial or book. Without comments it's very difficult to explain the logic of the program.
__________________
PFO's FAQ is here
Forum Rules

There is no cow level (Diablo III)
If you never push yourself you will never improve (Diablo III)
Ancient Dragon is offline   Reply With Quote
Old Jun 14th, 2013, 4:20 PM   #3
sixstringartist
Programming Guru

 
Join Date: Jun 2005
Posts: 1,333
Rep Power: 14 sixstringartist will become famous soon enough
Re: can someone explain this every statement?

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.
sixstringartist is offline   Reply With Quote
Old Jun 16th, 2013, 4:00 AM   #4
macteki
Professional Programmer
 
Join Date: Jul 2011
Posts: 437
Rep Power: 7 macteki will become famous soon enough
Re: can someone explain this every statement?

The program is buggy.
And I agree that you need to read a tutorial book.

; input a number from the console
; store the number in BX
; then test whether it is a leap year
Proc InputProc


mov ah, 01h  ; dos API, get character
int 21h
cmp al, 0dh  ; end of line ? (enter pressed)
je FirstTest ; yes, so test whether it is a leap year

mov ah, 0
sub al, 30h  ; convert ASCII into number

push ax      ; add the newly read digit(ax) to year (bx)
mov ax, 10d  ; formula is :
mul bx       ;   bx=bx*10+ax
pop bx       ; There is a potential bug : bx was not initialize
add bx, ax   ; at the beginning of InputProc

jmp inputProc  ; read next digit into ax

call FirstTest ; this line is impossible to reach, may remove it
ENDP

; first test, if bx is NOT divisible by 4, 
; then it is NOT a leap year
Proc FirstTest

mov ax, bx
push ax
mov bx, 004h
div bx
cmp dx, 0
je SecondTest  ; divisible by 4, still need to do second test
jmp leapFalse

RET
EndP

; second test, if BX is divisible by 4 
; but NOT divisible by 100,
; then it MUST be a leap year
Proc SecondTest
pop ax
push ax
mov bx, 0100h ; a bug here, 0100h is HEX, should use 100
div bx
cmp dx, 0
je ThirdTest  ; if divisible by 100, need further testing
jmp leapTrue
EndP

; third test, if BX is divisible by 400
; then it is a leap year
Proc ThirdTest

pop ax
mov bx, 0400h ; a bug here, should use 400, not 0400h
div bx
cmp dx, 0
je leapTrue
jmp leapFalse

EndP
__________________
API belongs to public. Knowledge belongs to yourself

http://java.macteki.com
macteki is offline   Reply With Quote
Old Jun 16th, 2013, 4:45 AM   #5
macteki
Professional Programmer
 
Join Date: Jul 2011
Posts: 437
Rep Power: 7 macteki will become famous soon enough
Re: can someone explain this every statement?

And I don't any benefits using a procedure declaration for each test instead of a simple label.

Assembly language can be (and should be) neatly structure.
__________________
API belongs to public. Knowledge belongs to yourself

http://java.macteki.com
macteki is offline   Reply With Quote
Old Jun 16th, 2013, 5:41 AM   #6
Ancient Dragon
Achieved Level 70

 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 4,345
Rep Power: 10 Ancient Dragon will become famous soon enoughAncient Dragon will become famous soon enough
Re: can someone explain this every statement?

The benefit of using procedure declaration is more readable code.
__________________
PFO's FAQ is here
Forum Rules

There is no cow level (Diablo III)
If you never push yourself you will never improve (Diablo III)
Ancient Dragon is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
why the sleep statement produces this result for our embedded ruby? bg.salunke09@gmail.com Ruby 0 Sep 6th, 2011 1:02 AM
Switch Statement error ignoreit C 3 May 4th, 2011 4:37 AM
I need to end a statement but don't know how Bluescreen Visual Basic 7 Jun 8th, 2009 2:46 PM
If statement not working?? squills C++ 9 Apr 10th, 2009 11:27 AM
Trouble with a swith statement cjaime C 10 Nov 8th, 2005 11:09 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:12 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC