Main, INPUT STORE operationcode load operationcode SUBT AddOperation SKIPCOND 800 JUMP Add load operationcode SUBT SubtractOperation SKIPCOND 800 JUMP Subtract load operationcode SUBT MultiplyOperation SKIPCOND 800 JUMP Multiply load operationcode SUBT DivideOperation SKIPCOND 800 JUMP Divide load operationcode SUBT MaximumOperation SKIPCOND 800 JUMP maxarr load operationcode SUBT MinimumOperation SKIPCOND 800 JUMP minarr load operationcode subt powerOperation Skipcond 800 Jump power load operationcode subt factorizationOperation Skipcond 800 Jump factorization load operationcode SUBT SineOperation SKIPCOND 800 JUMP Sine load operationcode SUBT CosineOperation SKIPCOND 800 JUMP Cosine load operationcode SUBT tanOperation SKIPCOND 800 JUMP Tan load operationcode load operationcode SUBT TriangleDetectionOperation SKIPCOND 800 JUMP TriangleDetection load operationcode load operationcode SUBT primeOperation SKIPCOND 800 JUMP primemethod HALT Add, JnS Inputmethod1 JnS Inputmethod2 load num1 add num2 store sum load sum output Halt Subtract, JnS Inputmethod1 JnS Inputmethod2 load num1 subt num2 store sum load sum output Halt Multiply, JnS Inputmethod1 JnS Inputmethod2 Load num2 Store ctr Clear Store sum Loopmul, Load sum Add num1 Store sum Load ctr Subt one Store ctr SkipCond 400 Jump Loopmul load sum Output Halt Divide, JnS Inputmethod1 JnS Inputmethod2 Clear Store Quotation Loopdiv, Load num1 Subt num2 Skipcond 000 jump AddQ jns Display halt AddQ, store num1 load Quotation Add one Store Quotation Jump Loopdiv Display, hex 0 load Quotation output load num1 store Reminder Load Reminder output JumpI Display maxarr, input Store x load array add x storeI array Output clear load size subt one store size load x store firstnum load maximum subt firstnum Skipcond 400 Skipcond 800 jns Max load size Skipcond 400 jump maxarr jump displaymax Max, hex 0 load firstnum store maximum jumpI Max displaymax, load maximum Output Halt minarr, input Store x load array add x storeI array Output load minimum skipcond 000 skipcond 800 jns inisializemin clear load size subt one store size load x store firstnum load minimum subt firstnum Skipcond 000 jns Min load size Skipcond 400 jump minarr jump displaymin Min, hex 0 load firstnum store minimum jumpI Min displaymin, load minimum Output Halt inisializemin, hex 0 load minimum add x store minimum JumpI inisializemin power, JnS Inputmethod1 JnS Inputmethod2 Load num1 Store ctr load num2 subt one store powerctr Clear Store sum jump bigloop bigloop, Load sum Add num1 Store sum Load ctr Subt one Store ctr SkipCond 400 Jump bigloop load powerctr subt one store powerctr load num1 store ctr load powerctr Skipcond 400 jump bigloop load sum Output Halt factorization,jnS Inputmethod1 load num1 store test Loopfact, Load num1 Subt factctr skipcond 400 jns loopctr load num1 subt factctr skipcond 400 jump Loopfact halt loopctr, hex 0 load factctr add one store factctr jumpI loopctr Addz, store test load Quotation Add one Store Quotation Jump Loopdiv Dis, hex 0 load Quotation output load num1 store Reminder Load Reminder output JumpI Display Sine, Halt Cosine, Halt Tan, Halt TriangleDetection, jns Inputmethod1 jns Inputmethod2 jns Inputmethod3 load num1 add num2 store firstadd load firstadd subt num3 store temp load temp skipcond 800 jump boolean clear store temp load num1 add num3 store secondadd load secondadd subt num2 store temp load temp skipcond 800 jump boolean clear store temp load num2 add num3 store thirdadd load thirdadd subt num1 store temp load temp skipcond 800 jump boolean load check output Halt Inputmethod1, hex 0 Input store num1 JumpI Inputmethod1 Inputmethod2, hex 0 Input store num2 JumpI Inputmethod2 Inputmethod3, hex 0 input store num3 jumpI Inputmethod3 boolean,load check1 subt one store check1 load check1 Output Halt primemethod, Jns Inputmethod1 load two store i load num1 subt one store u loop, load i store i1 load num1 store temp jump div check1, load reminder skipcond 400 jump next jump prime next, load i add one store i load i subt u Skipcond 000 jump notprime jump loop div,load temp subt i1 skipcond 000 jump add1 jump divout add1, store temp load Q add one store Q jump div divout, load temp store Reminder jump check1 notprime, load zero output halt prime, load one output halt AddOperation, DEC 1 SubtractOperation, DEC 2 MultiplyOperation, DEC 3 DivideOperation, DEC 4 MaximumOperation, DEC 5 MinimumOperation, DEC 6 powerOperation, dec 7 factorizationOperation, dec 8 SineOperation, DEC 9 CosineOperation, DEC 10 tanOperation, Dec 11 TriangleDetectionOperation, DEC 12 primeOperation, dec 13 operationcode, dec 0 i,dec 0 u, dec 0 i1, dec 0 reminder, dec 0 num1,dec 0 num2, dec 0 num3, dec 0 ctr, dec 0 sum, dec 0 Q,dec 0 zero, dec 0 one, dec 1 two, dec 2 three, dec 3 four,dec 4 five, dec 5 maximum, dec 0 minimum, dec 0 Quotation, dec 0 Reminder, dec 0 size, dec 5 firstnum, dec 0 x, dec 0 powerctr,dec 0 firstadd, dec 0 secondadd, dec 0 thirdadd, dec 0 temp, dec 0 check,dec 1 factctr,dec 2 test, dec 0 array, hex 0 dec 0 dec 0 dec 0 dec 0 dec 0
Write, Run & Share Assembly code online using OneCompiler's Assembly online compiler for free. It's one of the robust, feature-rich online compilers for Assembly language. Getting started with the OneCompiler's Assembly compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as Assembly
and start coding.
Assembly language(asm) is a low-level programming language, where the language instructions will be more similar to machine code instructions.
Every assembler may have it's own assembly language designed for a specific computers or an operating system.
Assembly language requires less execution time and memory. It is more helful for direct hardware manipulation, real-time critical applications. It is used in device drivers, low-level embedded systems etc.
Assembly language usually consists of three sections,
Data section
To initialize variables and constants, buffer size these values doesn't change at runtime.
bss section
To declare variables
text section
_start
specifies the starting of this section where the actually code is written.
There are various define directives to allocate space for variables for both initialized and uninitialized data.
variable-name define-directive initial-value
Define Directive | Description | Allocated Space |
---|---|---|
DB | Define Byte | 1 byte |
DW | Define Word | 2 bytes |
DD | Define Doubleword | 4 bytes |
DQ | Define Quadword | 8 bytes |
DT | Define Ten Bytes | 10 bytes |
Define Directive | Description |
---|---|
RESB | Reserve a Byte |
RESW | Reserve a Word |
RESD | Reserve a Doubleword |
RESQ | Reserve a Quadword |
REST | Reserve a Ten Bytes |
Constants can be defined using
CONSTANT_NAME EQU regular-exp or value
%assign constant_name value
%define constant_name value
Loops are used to iterate a set of statements for a specific number of times.
mov ECX,n
L1:
;<loop body>
loop L1
where n specifies the no of times loops should iterate.
Procedure is a sub-routine which contains set of statements. Usually procedures are written when multiple calls are required to same set of statements which increases re-usuability and modularity.
procedure_name:
;procedure body
ret