CrazyBoss Posted September 9, 2015 Share Posted September 9, 2015 Hello. Do the compiler calculate math before compiling ? I mean a=1+2+3+4+a will be the same as a=10+a make the same size of asm code? Quote Link to comment Share on other sites More sharing options...
Kiwi Posted September 9, 2015 Share Posted September 9, 2015 I compiled and it generated this code ;[13] c=1+2+3+4+c SRCFILE "bats.bas",13 MVII #10,R0 ADD V3,R0 MVO R0,V3Seems like it added all the number to get 10. Quote Link to comment Share on other sites More sharing options...
CrazyBoss Posted September 9, 2015 Author Share Posted September 9, 2015 thats good so no need to worry to use math in the code you know sometimes you make something like a=a+20+5+(2*a) i did experience that sometimes you need to use () where your normal dont have to (compared to other basics or pascal). actually I think inty basic do it "wrong" if you dont use the () in this example: a=10+(5*a) Quote Link to comment Share on other sites More sharing options...
+nanochess Posted September 9, 2015 Share Posted September 9, 2015 thats good so no need to worry to use math in the code you know sometimes you make something like a=a+20+5+(2*a) i did experience that sometimes you need to use () where your normal dont have to (compared to other basics or pascal). actually I think inty basic do it "wrong" if you dont use the () in this example: a=10+(5*a) IntyBASIC has standard precedence rules. The multiply and division operators have higher precedence than the addition and substraction operators. So the expression will work just fine without parenthesis. Quote Link to comment Share on other sites More sharing options...
artrag Posted September 9, 2015 Share Posted September 9, 2015 (edited) It has problems due to signs and byte and words. Division is only signed, product is 16 bit even between bytes and is silently truncated to bytes but it should deal correctly with precedence among operators. Actully due to the integer nature of the variables you can have problems according to the order of products and divisions. A/5*8 is very different by A*8/5 Edited September 9, 2015 by artrag Quote Link to comment Share on other sites More sharing options...
intvnut Posted September 9, 2015 Share Posted September 9, 2015 It has problems due to signs and byte and words. Division is only signed, product is 16 bit even between bytes and is silently truncated to bytes but it should deal correctly with precedence among operators. Actully due to the integer nature of the variables you can have problems according to the order of products and divisions. A/5*8 is very different by A*8/5 Does it behave much differently than C here? Because division and multiplication are at the same precedence, I would expect A/5 to truncate before the multiplication. Maybe it's less surprising to me because I've been programming C for so long. If you're coming from a Microsoft BASIC background (which is many or most of us who learned BASIC in the 80s) where everything is floating point by default, I can definitely see how it can be a surprise. Quote Link to comment Share on other sites More sharing options...
artrag Posted September 9, 2015 Share Posted September 9, 2015 (edited) No, coding in c it is normal. You have only to know that here bytes are unsigned by default (now can be also signed) and that division is unsigned The main difference anyway is with old basic where everything is float by default and all integers are signed 16 bit. But none needs floats here, it isn't a feature request. Edited September 9, 2015 by artrag 1 Quote Link to comment Share on other sites More sharing options...
intvnut Posted September 9, 2015 Share Posted September 9, 2015 No, coding in c it is normal. You have only to know that here bytes are unsigned by default (now can be also signed) and that division is unsigned The main difference anyway is with old basic where everything is float by default and all integers are signed 16 bit. But none needs floats here, it isn't a feature request. Makes sense. I figured you were speaking from the perspective of someone who grew up with a floating-point BASIC. And yeah, implementing floating point on the Intellivision would be a bad idea. I didn't think you were requesting it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.