|
|
|
|
| Welcome, Guest | Home | Search | Login | Register | |
| Author | Random Dev Question (Read 20034 times) | ||||||||||||||||||||||
|
cballero
1024 MB ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1176 System 7, today and forever |
on: March 22, 2024, 10:36
I've been looking at the dev side of things just a little and wanted to see with those that know more than me how the following code below looks; the target was coding a simple Mac watch app! ![]() .data ; Define memory locations for storing time variables seconds: .word 0 ; Stores current seconds (0-59) minutes: .word 0 ; Stores current minutes (0-59) hours: .word 0 ; Stores current hours (0-23) .text .global _start ; Program entry point _start: ; Initialization clr.w seconds ; Clear seconds to 0 clr.w minutes ; Clear minutes to 0 clr.w hours ; Clear hours to 0 loop: ; Simulate time passage (replace with actual timer) addq.b #1, seconds ; Increment seconds ; Check for overflow (seconds reaching 60) cmp.w #60, seconds beq carry, update_minutes ; Jump to update minutes if overflow ; Loop back to display current time bra loop update_minutes: clr.w seconds ; Reset seconds to 0 addq.b #1, minutes ; Increment minutes ; Check for overflow (minutes reaching 60) cmp.w #60, minutes beq carry, update_hours ; Jump to update hours if overflow ; Loop back to display current time bra loop update_hours: clr.w minutes ; Reset minutes to 0 addq.b #1, hours ; Increment hours ; Check for overflow (hours reaching 24) cmp.w #24, hours beq carry, loop ; Loop back if not overflow ; Reset hours for a new day clr.w hours bra loop ; Display logic (replace with your preferred output method) ; This section needs further development based on your target environment ; End of program halt ; Halt the program Just keep in mind I know next to nothing outside of a couple of BASIC and PASCAL programming courses I took in college, so you have to take it slow and dumb things down, at least for me!
|
||||||||||||||||||||||
|
Bolkonskij
|
Administrator 1024 MB ![]() ![]() ![]() ![]() ![]() Posts: 2023
Reply #1 on: March 26, 2024, 15:21
|
Pushing it because it does deserve a good answer ![]() Unfortunately, this is Pascal (?) and me and Pascal have only been briefly aquainted. I hope somebody else can help you!
Last Edit: April 08, 2024, 09:09 by Bolkonskij
|
ShinobiKenobi
|
256 MB ![]() ![]() ![]() ![]() ![]() Posts: 362 System 7 fan
Reply #2 on: March 27, 2024, 00:34
|
I've forgotten the syntax of Pascal, but that looks similar to assembly.
|
cballero
|
1024 MB ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1176 System 7, today and forever
Reply #3 on: March 27, 2024, 17:54
|
Luckily, I did do one class in PASCAL and it was also used in the Mac and DOS development team I worked alongside with at a company I worked for many years ago. It was years ago, and you nailed it, SK: I was shooting at Assembly language since it can be so darn fast on our Macs (even when the code is interpreted: think of examples like WriteNow on PowerMacs) but so challenging to code with as well.
|
ShinobiKenobi
|
256 MB ![]() ![]() ![]() ![]() ![]() Posts: 362 System 7 fan
Reply #4 on: March 28, 2024, 06:42
|
I like assembly. I wouldn't call myself an expert, though.
Last Edit: March 28, 2024, 21:57 by ShinobiKenobi
|
lauland
|
512 MB ![]() ![]() ![]() ![]() ![]() Posts: 674 Symtes 7 Mewconer!
Reply #5 on: April 08, 2024, 02:37
|
I hadn't seen the "beq carry,LABEL" syntax, but only "bcc" and "bcs" (carry clear, carry set). Be careful, it's a very common mistake to check carry when you really mean equal...it could cause you to actually skip 60! And, hopefully the assembler you'd use interprets the constants like #24 and #60 as decimal (and not hex by default!). It's nitpicking, but I try to never mix sizes...in this case it doesn't matter if it's bytes or words, but I'd just use "add.w" and not "addq"...not that it should ever overflow 256, but just to be safe. If you're targeting '020 or higher, I'd use long's (32 bit) for natural alignment. You aren't really saving a lot of time using words there. And of course you'd never use an actual halt instruction unless you are running on an embedded platform!
|
|
Pages: [1]
|
| ||||||
|
© 2021 System7Today.com. |




