Comparison of Assembly and C Syntax
Assembly | C
------------------------------|------------------------------------
; Use a name instead of a num | /* Use a name instead of a num */
COUNT = 5 | #define COUNT 5
;-----------------------------| /*-----------------------------*/
;start a program | /* To start a program */
.area CODE (ABS) | main()
.org 0x0100 | {
lds #0x01FF | }
;-----------------------------| /*-----------------------------*/
;allocate two bytes for | /* Allocate two bytes for
;a signed number | * a signed number */
|
.area DATA (ABS) |
.org 0x0000 |
i .ds 2 | int i;
j .dw 0x1A00 | int j = 0x1a00;
;-----------------------------| /*-----------------------------*/
;allocate two bytes for | /* Allocate two bytes for
;an unsigned number | * an unsigned number */
|
i .ds 2 | unsigned int i;
j .dw 0x1A00 | unsigned int j = 0x1a00;
;-----------------------------| /*-----------------------------*/
;allocate one byte for | /* Allocate one byte for
;an unsigned number | * an unsigned number */
|
i .ds 1 | unsigned char i;
j .db 0x1F | unsigned char j = 0x1f;
;-----------------------------| /*-----------------------------*/
;Get a value from an address | /* Get a value from an address */
|
i .ds 1 | unsigned char *ptr, i;
|
ldx #0xE000 | ptr = 0xE000;
ldaa 0,x | i = *ptr;
staa i |
;-----------------------------| /*-----------------------------*/
;To call a subroutine | /* To call a function */
ldaa i | sqrt(i);
jsr sqrt |
;-----------------------------| /*-----------------------------*/
;To return from a subroutine | /* To return from a function */
ldaa j | return j;
rts |
;-----------------------------| /*-----------------------------*/
;flow control | /* Flow control */
blo | if (i < j)
blt | if (i < j)
|
bhs | if (i >= j)
bge | if (i >= j)
|