Sign in to follow this  
Followers 0
pr2501

sub(31)

5 posts in this topic

If the first number is bigger than second: then it's OK. But if it is opposite I get (for me) understandable value (like in the code above). What must I do (in what way is it possible) to get value like absolute number. To make myself clear: #30 = 48 -#40 = 64 ----------- FFFFFFFFFFF0= - 16 For my application in need absolute value: in my case 16 #30 = 48 -#40 = 64 ----------- #10 = 16 LD P_On MOV(21) #30 DM100 LD P_On BCD(24) DM100 DM102 LD P_On MOV(21) #40 DM103 LD P_On BCD(24) DM103 DM104 LD P_On SUB(31) DM102 DM104 DM105 LD P_On MOV(21) #30 DM100 LD P_On BCD(24) DM100 DM102 LD P_On MOV(21) #40 DM103 LD P_On BCD(24) DM103 DM104 LD P_On SUB(31) DM102 DM104 DM105 odstevanje.cxp

Share this post


Link to post
Share on other sites
First, do a compare which of the two numbers is the biggest. So, CMP(20) [NUMBER1] with [NUMBER2] If result GT (255.05), move [NUMBER1] in 1st operand of the SUB instruction. Result LT(255.07), move [NUMBER2] in 1st operand of SUB instruction. Result EQ (255.06), doesn't matter SUB result is 0. In your case CMP #48 #64 P_GT move #48 in first operand of SUB P_LT move #64 in first operand of SUB (this line will be true) P_EQ move 0 in SUB result So SUB will be #64 -#48 ------- 16 Hope this helps.

Share this post


Link to post
Share on other sites
HI You can use carry flag (255.04) to indicate when the result of subraction is negative take a look at this

Share this post


Link to post
Share on other sites
In this way it works: LD P_On MOV(21) #30 DM140 LD P_On MOV(21) #40 DM141 LD P_On CMP(20) DM140 DM141 LD P_GT MOV(21) DM140 DM142 MOV(21) DM141 DM143 LD P_LT MOV(21) DM141 DM142 MOV(21) DM140 DM143 LD P_On SBB(51) DM142 DM143 DM145 Tank you Maybe lately I'll understand second reply too .

Share this post


Link to post
Share on other sites
OK! I made some modifications to your programm run it and it would be more easy for you to understand it. odstevanje_2_.cxp I forgot the program

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0