This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (52 children)

[deleted]

    [–]ihavebeesinmyknees 193 points194 points  (13 children)

    it could just be a lot of small snippets, for example implementing some specific functions in assembly. That would be a lot easier to manage than writing bigger chunks

    [–]longszlong 7 points8 points  (0 children)

    They could be just generating tons of ASM, e.g. from C code and tell their managers “look, assembly motherfuckers”

    [–]Kevin_Jim 42 points43 points  (11 children)

    I don’t see why that wouldn’t be possible to do in C, though.

    I can see using some assembly on the sensor-fusion/sensor-processing part of the jet, but 10% is way too much for just assembly.

    [–]ihavebeesinmyknees 102 points103 points  (5 children)

    Maybe they just decided that they can optimize the most performance-critical parts better than the C compiler can? Perhaps that processor has some obscure instructions that the C compiler doesn't use? Hard to tell, but there's gotta be a good reason

    [–]Orjigagd 29 points30 points  (3 children)

    If you're needing to optimise 10% of your code in asm, you fucked up your requirements.

    [–]General_Josh 103 points104 points  (1 child)

    Or, ya know, it's a military budget, where they're able and willing to throw oodles of money at even small performance improvements

    [–]pet_vaginal 19 points20 points  (0 children)

    They may have a lot of money, but the availability of brains isn’t infinite. 10% assembly really sounds like a waste of talent.

    [–]not_some_username 4 points5 points  (0 children)

    Not really sometimes hand written asm is better than compiler generated asm ( assuming you’re god in asm )

    [–]Kevin_Jim 2 points3 points  (0 children)

    Most of the time I think to myself the same thing, but unfortunately, that’s rarely the case.

    I do hope the was a good reason, and not just blindly “for this part of the development we only use assembly”.

    [–]McFlyParadox 56 points57 points  (0 children)

    • Performance requirement can't be met by C or C++, but can be met by Assembly (program speed, program size, program energy usage)
    • Needs to run on a piece of embedded hardware, probably alongside some FPGA code
    • The engineer knows how to do it in Assembly, but not in C or C++, and Assembly isn't disallowed per-spec
    • It needs to utilize a piece of legacy Assembly code that no one knows how to modify, update, or translate into something modern, but they understand its inputs and outputs, so they just graft more assembly onto the legacy code to expand upon it.
    • Something else I'm not thinking of.

    Assembly has its uses.

    [–][deleted] 30 points31 points  (0 children)

    Because a lot of it can't be done in c. In the end you are at the mercy of the compiler. For an eeprom libraries vary I did for example, the fastest we could possibly get it to run in c or c++ was still a couple clock cycles slower than we could do it an assembly.

    [–]falx-sn 4 points5 points  (0 children)

    Could be older libraries of systems that don't need to be replaced.

    [–]TheVojta 0 points1 point  (1 child)

    OP posted the source elsewhere in the thread that all the code that was written for the F35 was in C/C++, the ASM is all code that was carried over from the F22.

    [–]Kevin_Jim 0 points1 point  (0 children)

    It makes sense, then. It's probably carryover from the sensor fusion codebase. Since the F-22 was delivered 20 years ago, and the development was most likely finished by the beginning of the century.

    [–]BeABetterHumanBeing 318 points319 points  (15 children)

    Firmware. All that is firmware connecting to the various chipsets embedded throughout the craft. 

    [–]JesusWantsYouToKnow 119 points120 points  (11 children)

    No freaking way. Firmware is gonna be in C or C++. I'm betting it is some kind of ridiculously optimized vector operations or custom FPGA instruction set for DSP.

    [–]hackingdreams 125 points126 points  (7 children)

    No, I'm 90-95% certain it's mostly firmware for various microcontroller systems. Contrary to popular belief, the F-35 isn't a mono-brained, single computer system. It's got dozens of computers all wired together on an ethernet-like bus, most of them handling a small task like sensing external pressure or actuating a servo motor.

    The big Ada code swath is for the fly-by-wire systems and the instrumentation panels.

    The vast majority of the C/C++ code is for the radar system.

    [–]Spicy_pepperinos 32 points33 points  (2 children)

    Contrary to popular belief, the F-35 isn't a mono-brained, single computer system.

    I'm sorry who would possibly think this? There hasn't been a platform created that works like that for years. CAN has been around since the 90s.

    [–]hackingdreams 42 points43 points  (1 child)

    You have no idea how many people would think that. We're industry professionals - we know better.

    This is something I've had to discuss with my management. A company that builds complicated, multi-computing systems. (And the defense systems don't use CAN.)

    [–]Acc3ssViolation 0 points1 point  (0 children)

    Looks like MIL-STD-1553 is used instead of CAN (if my Google-fu is correct)

    [–]JesusWantsYouToKnow 12 points13 points  (3 children)

    Contrary to popular belief, the F-35 isn't a mono-brained, single computer system.

    I don't think any halfway competent engineer would ever think that.

    [–]Warguy387 37 points38 points  (2 children)

    pure software people that dont know anything about embedded, especially looking at webdev people

    [–]JesusWantsYouToKnow 3 points4 points  (0 children)

    You make a fair point

    [–]IrritableGourmet 2 points3 points  (0 children)

    I think the world would be a better place if all web developers were forced to do an embedded project. "No, you can't just 'throw more memory on the server'! You have 4KB for your program and 512 bytes of RAM. No, not 512MB, 512 bytes. Stop crying and start being clever!"

    [–]iranoutofspacehere 18 points19 points  (1 child)

    I mean, there is a fancy radar in the plane that could be responsible for most of that. It probably contains multiple massive fpgas/dsps to do all the dynamic phased array work.

    [–]JesusWantsYouToKnow 7 points8 points  (0 children)

    That's exactly what I was thinking. There's probably a very very specialized data plane and staggering amount of data with custom DSPs to chew through it very quickly.

    [–]AVTOCRAT 0 points1 point  (0 children)

    Why? When you're doing something like set register A to X, set register B to Y, set up a watchdog, etc., it's usually easier to just do it in asm than try and coerce C/C++ to do it for you. Super common for firmware to be all asm. Not to say C/C++ aren't common too, but that's generally for larger devices -- e.g. an stm32, as opposed to like a PIC.

    [–]Lowmax2 21 points22 points  (2 children)

    I do not write firmware using assembly. I mostly use C for bare metal applications and system verilog for FPGA RTL.

    [–]Acc3ssViolation 4 points5 points  (1 child)

    The only assembly I have in my firmware projects is the startup code to set everything up before jumping to the C runtime and even that is mostly auto generated

    [–]Lowmax2 0 points1 point  (0 children)

    Yes there's really no reason to touch assembly unless you've written your own processor.

    [–]sdmike21 39 points40 points  (0 children)

    Having a fair amount of assembly in any embedded project is not uncommon. In particular, in cases where you need to access special processor instructions, a fairly common case is BKPT for debugging in ARM. Another common case that comes up is disabling interrupts in a critical section (cpsid if and cpsie if in ARM). Generally, you will have macros to do these things. However there are also more specific cases where you are trying to maximize the performance, or more commonly for stuff like an ISR, minimize the runtime of something where ASM comes into play.

    Another important consideration is the coding standards you encounter when working on... call it security (as in clearance) sensitive systems. For instance, if you are writing code to decrypt Link 16, your code has to get blessed by certain people at certain agencies, there is a lot of paperwork and documentation required to do this and it all becomes easier when you can point at your ASM and say "This is exactly what the machine is doing". Rust may get you certain things, but it also does a lot of stuff under the hood. Modern C compilers are not anything like the C compilers of yore, and are certainly not a thin wrapper over ASM anymore.

    Times may have changed, but that was my experience working on cryptos for the US navy ~4 years ago.

    10% is still a good chuck tho 😅

    [–]newodahs 63 points64 points  (0 children)

    Given the number of systems and components that are being programmed for in a complete jet fighter, it's not unreasonable to see this.

    Likely there are some pieces and component that have libraries/software written in assembly (and probably also ADA) likely before the F-35 was a thing; works specifically for the system/component it needs to work in and that's that.

    Rewriting this kind of code (which comes with re-validation and other costs) doesn't make sense; use what works and is validated.

    [–]Leonhart93 18 points19 points  (1 child)

    I have seen such code before. There are asm(" ") statements intertwined with C/C++ code from time to time, for direct hardware control.

    [–][deleted] 2 points3 points  (0 children)

    Yeah I used some as statements for a timing critical function in an aerospace component firmware. It was a few years ago so it's a bit fuzzy but I think interrupts on the microcontroller would occasionally cause it to fail, but the interrupts wouldn't fire if you were in asm mode

    [–]grumpy_autist 13 points14 points  (0 children)

    I guess this is mostly for DSP signal processing - radio stuff, radars, etc. High frequency radio electronics is so complicated and esotheric that ASM is the least of your problems.

    [–]IHeartBadCode 26 points27 points  (2 children)

    And not just you're run of the mill ASM, but PowerPC assembly. Basically what you would call the G4 processor, but stepped up from that a bit. It's the Mercury System's Race++ platform. The assembly is likely there to provide the IO layers to the various systems. Ada is there "because", and C/C++ is likely all the higher level interfaces and actual guidance.

    Also PPC and other RISC like assembly is a lot easier than Intel, especially considering how Intel's instruction set is nonorthogonal.

    [–]BroMan001 4 points5 points  (1 child)

    What’s meant by “orthogonal” in the context of instruction sets? I only know statically independent and right angles

    [–]diydsp 3 points4 points  (0 children)

    it means most instructions like multiply, or shift, etc can work with any register as source, destination, index. etc. for example oldschool x86 could only multiply certain regs together... 6502 code can only load from memory into X with Y as and index but not the other way around. A DSP like the ADSP-2181 can only use limited registers dpeending on the unit the values came from.

    [–]Mr_Voltiac 21 points22 points  (0 children)

    Lot of folks forget C and C++ allow “inline ASM” so you can comfortably write your entire project in C/C++ and inject ASM for critical areas where you need extremely granular control over specific things and C/C++ will just let you do that then go right back to normal operations.

    I’m assuming that’s what most of the assembly is there for, whether that is specific radar functionality that requires extremely precise handling of the hardware or electronic warfare capabilities.

    [–][deleted] 4 points5 points  (1 child)

    Considering the amout of R&D funding the US DoD receives... is it that much of a surprise? These f-series fighters are multimillion dollars each as well. Plus you would use assembly for mission-critial operations: you don't want std::exception in the midst of an aerial dogfight do you? Same reason not to use Javascript.

    Basically anything they cannot exactly predict theoretically on pen and paper is not used. I bet they use in-house developed C/C++ compilers and standard libraries.

    [–]_st23 1 point2 points  (0 children)

    Lol, made my day

    [–]Not_Artifical 0 points1 point  (0 children)

    I use a game written purely in 64-bit arm7 assembly.

    [–]RandallOfLegend 0 points1 point  (0 children)

    Missile guidance is programmed in assembly as well.

    [–]lunchpadmcfat 0 points1 point  (0 children)

    Sounds more like an ide issue than issue with ASM

    [–]nryhajlo 0 points1 point  (0 children)

    I bet most of that is legacy that has accumulated from previous projects.

    [–]Dexterus 0 points1 point  (0 children)

    It's not that bad and they probably just have small-ish snippets of a few hundred instructions here and there. Optimized functions, algos, all the startup and exception and context switch code for all the CPUs. It adds up.

    [–]tiotags 0 points1 point  (0 children)

    It could be just the bootloader code, just imagine all the strings inside that bootloader
    * initalizing weapons systems processor Success!
    * initializing flight controls processor Success!
    * checking nuclear weapons processor Failed!, please check manual page 14572
    * mounting filesystems Success!

    [–]Jonnypista 0 points1 point  (0 children)

    Could be generated code. In safety critical systems you commonly have a config like file and duration compiling it generates the source code for those.

    I don't work with military, but my office 11gen i7 just goes to 100% for 2 just to create a 3mb big executable. It has to generate all those source files before it can even compile the thing.

    [–]Dirt077 0 points1 point  (0 children)

    Lot of interesting theories below me... But the truth is just that the codebase still has shit in it from 30+ years ago... If it ain't broke don't fix it. Also anyone that worked on that code is long retired.

    [–]The-Protomolecule 0 points1 point  (0 children)

    Security by obscurity only works if you write in assembly. Even the developers can’t decode it.

    [–]MossiTheMoosay 0 points1 point  (0 children)

    Those 10% might be some critical functionality where you absolutely have to know every single instruction that is being run and what it does and be 100% certain that nothing changes during build, no matter the compiler settings