Skip to content

Instantly share code, notes, and snippets.

@auriza
Last active March 15, 2021 08:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save auriza/bd2fefc14903d5a1973cb510ab6f07cb to your computer and use it in GitHub Desktop.
Save auriza/bd2fefc14903d5a1973cb510ab6f07cb to your computer and use it in GitHub Desktop.
OAK -- Latihan UTSP
global main
extern scanf, printf
section .data
fmt_in db "%d %d %d", 0
fmt_out db "%d", 10, 0
section .bss
p resd 1
l resd 1
t resd 1
section .text
main:
push t
push l
push p
push fmt_in
call scanf ; scanf("%d %d %d", &p, &l, &t)
add esp, 16
mov eax, [p] ; eax = p * l * t
mul dword [l]
mul dword [t]
push eax
push fmt_out
call printf ; printf("%d\n", eax)
add esp, 8
mov eax, 0 ; return 0
ret
global main
extern scanf, printf
section .data
fmt_in db "%d", 0
kempes db "kempes", 10, 0
pas db "pas", 10, 0
keras db "keras", 10, 0
section .bss
psi resd 1
section .text
main
push psi
push fmt_in
call scanf ; scanf("%d", &psi)
add esp, 8
mov eax, [psi]
cmp eax, 29 ; if (psi < 29)
jb .kempes ; goto .kempes
cmp eax, 35 ; if (psi <= 35)
jbe .pas ; goto .pas
jmp .keras ; goto .keras
.kempes
push kempes
jmp .print
.pas
push pas
jmp .print
.keras
push keras
.print
call printf
add esp, 4
mov eax, 0 ; return 0
ret
global main
extern scanf, printf
section .data
fmt_in db "%d", 0
fmt_out db "%d", 10, 0
section .bss
n resd 1
section .text
main
push n
push fmt_in
call scanf ; scanf("%d", &n)
add esp, 8
mov eax, 1 ; f = 1
mov ecx, 1 ; i = 1
.fact
cmp ecx, [n]
ja .fact_end ; while (i <= n)
mul ecx ; f = f * i
inc ecx ; i++
jmp .fact
.fact_end
push eax
push fmt_out
call printf ; printf("%d\n", eax)
add esp, 8
mov eax, 0 ; return 0
ret
global main
extern scanf, printf
section .data
M dd 17, 14, 24, 11, 18
dd 21, 6, 13, 19, 25
dd 10, 22, 20, 12, 7
dd 3, 15, 23, 5, 1
dd 8, 4, 9, 16, 2
fmt_in db "%d", 0
fmt_out db "%d", 10, 0
section .bss
d resd 1 ; diagonal
section .text
main:
push d
push fmt_in
call scanf ; scanf("%d", &d)
add esp, 8
imul edi, [d], 5 ; idx = d * cols + d
add edi, [d]
mov eax, [M + edi*4] ; eax = M[idx]
push eax
push fmt_out
call printf ; printf("%d\n", eax)
add esp, 8
mov eax, 0 ; return 0
ret

1. Volume Balok

Buatlah program untuk menghitung volume balok dari masukan panjang, lebar, dan tinggi yang diberikan.

Contoh Masukan

5 4 3

Contoh Keluaran

60

2. Tekanan Ban

Buatlah program untuk mengklasifikasikan tekanan ban sesuai rentang berikut:

  • < 29: kempes
  • 29--35: pas
  • 35: keras

Contoh Masukan

33

Contoh Keluaran

pas

3. Faktorial

Buatlah program untuk menghitung faktorial bilangan n dari masukan yang diberikan. Berikut potongan kode untuk menghitung nilai faktorial n:

    f = 1;
    i = 1;

    while (i <= n) {
        f = f * i;
        i++;
    }

    printf("%d\n", f);

Contoh Masukan

5

Contoh Keluaran

120

4. Diagonal Matriks

Buatlah program untuk menampilkan elemen diagonal suatu matriks. Berikut isi dari matriks tersebut:

    [ 17 14 24 11 18 ]
    [ 21  6 13 19 25 ]
M = [ 10 22 20 12  7 ]
    [  3 15 23  5  1 ]
    [  8  4  9 16  2 ]

Contoh Masukan

1

Contoh Keluaran

6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment