| C/C++ | Pep/9 | NASM | Description |
|:------------------------- | ----------------------------------- | --------------------- | ------------------------- |
| | | section .data | Global variables: |
| char ch; | .block 1 | char resb 1 | char(1 byte) |
| int num; | .block 2/.word 2 | num dw 0 | integer |
| | | | Local variables |
| int num; | .equate 0 ;local #2d | equ 0 ; 2 bytes | integer |
| char ch; | .equate 0 ;local #1c | | character |
| | | | paramenters |
| int fib(int n) | .equate 0 ;local #2d | ebp | in 'fib' function |
| void fib(int &sum) | .equate 0 ;formal#2h | | |
| void fib(int ary[]) | .equate 0 ;formal#2h | | |
| | msg: .ASCII "msg \x00" | msg db "mgg", 0xA,0xD | message |
| | | len1 equ $- msg1 | |
| int theArray[] = {3,-1.}; | theArray: .BLOCK 12 ; global #2d6a | global theArray | global array 6 cell |
| | array: .WORD 3 | theArray: dw 3 | |
| | .WORD -1 | dw -1 | |
| | .WORD 5 | dw 5 | |
| | .WORD 2 | dw 2 | |
| | .WORD 6 | dw 6 | |
| | .WORD -8 | dw -8 | |
| | index: .BLOCK 2 | | space for 1 integer[i] |
| | | | |
| | theArray:.EQUATE 0 ; local #2d6a | | local array |
| | | | |
| | STRO msg,d | mov ecx,msg | print message |
| | | mov edx,len | |
| | DECI num,d | mov [num],word 0 | user input(global) |
| | DECO num,d | | user output (global) |
| | LDBA charIn,d |mov ecx,0->mov cl,[ebx]| input a character |
| | STBA ch,d |push cl | save a character |
| | LDBA charIn,d | | input the newline |
| | LDBA ch,d | | toss newline, reload |
| | CPBA 'A',i | | compare a character |
| | STBA charOut,d | | output the character |
| | | | |
| for (int k=3; k < 9; k++) | LDWA 3,i | mov eax,3 | load 3 into A |
| | STWA k,d | for: mov [k],eax | store in k |
| | for: LDWA k,d | mov eax,[k] | for loop |
| | CPWA 9,i | CMP eax,9 | k >= 9? |
| | BRGE endFor | JGE endFor | yes |
| | ADDA 1,i | add eax,1 | if no -> k++ |
| | STWA k,d | mov [k],eax | store in k |
| | BR for | jmp for | return to for |
| | | | |
| | ADDA num2,d | | add num2 |
| | SUBA num2,d | sub ebx,[num2] | substract num2 |
| | NEGA | neg | negate |
| | | | |
| | SUBSP | push ax /sub esp,2 | push the stack |
| | ADDSP | pop ax | popthe stack |
| | MOVSPA | | mov stack pointer |
| | ASLX | mul dx | |
| | ASRX | | |
| switch (letter) { | letters: .ADDRSS caseA | | switch statement |
| case 'A':countA++; break; | caseA: LDWX countA,s | | |
| | ADDX 1,i | | countA++ |
| | STWX countA,s | | |
| | BR endCase | | ;break |
| | | | |
| struct node{ | next: .EQUATE 0 ;struct field #2h | | linked list |
| node* next; | data: .EQUATE 2 ;struct field #2d | | |
| int data; } | | | |
| void insert(node*& ptr) { | ptr: .EQUATE 0 ;local variable #2h | | |
| node* temp = new node; | LDWA 4,i | | 4(space for 2 int(malloc |
| temp->next = ptr; | CALL malloc;allocate #next #data | | |
| temp->data = val; | STWX temp,s | | |
| ptr = temp; } | LDWA val,s | | |
| | LDWX data,i | | |
| | STWA temp,sfx | | |
| | LDWA node,sf | | sfx - locals, n - globals |
| | LDWX next,i | | |
| | STWA temp,sfx | | |
| | LDWA temp,s | | |
| | STWA node,sf | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |