1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
; nasm -f win32 operations.asm
; gcc -o test calcul.o operations.obj asm_io.obj
%include "asm_io.inc"
%define NL 10
;
; initialized data is put in the .data segment
;
segment .data
;
; These labels refer to strings used for output
;
choixNum1 db "Entrez un premier numero: ", 0
choixNum2 db "Entrez un deuxieme numero: ", 0
choixOperation db "Choissisez l'operation",0
choixAdd db "Tapez 1 pour l'addition ",0
choixSub db "Tapez 2 pour la soustraction ",0
choixMul db "Tapez 3 pour la multiplication ",0
choixDiv db "Tapez 4 pour la division ",0
choix db "Votre choix : ",0
moins db " - ",0
plus db " + ",0
fois db " * ",0
divise db " / ",0
egal db " = ",0
nl db NL,0
;
; uninitialized data is put in the .bss segment
;
segment .bss
;
; These labels refer to double words used to store the inputs
;
choixCalcul resb 1
num1 resd 1
num2 resd 1
;
; code is put in the .text segment
;
segment .text
global _asm_calculatrice
_asm_calculatrice:
enter 0,0 ; setup routine
pusha
; --------------------------------Choix du nombre 1 --------------------------------
mov eax, choixNum1
call print_string
call read_int
mov [num1], eax
mov eax,[num1]
call print_nl
call print_int
call print_nl
; -------------------------------- Choix du nombre 2 --------------------------------
mov eax, choixNum2
call print_string
call read_int
mov [num2], eax
mov eax,[num2]
call print_nl
call print_int
call print_nl
; -------------------------------- Choix de l'operation -----------------------------
mov eax, choixOperation
call print_string
call print_nl
mov eax, choixAdd
call print_string
call print_nl
mov eax, choixSub
call print_string
call print_nl
mov eax, choixMul
call print_string
call print_nl
mov eax, choixDiv
call print_string
call print_nl
mov eax, choix
call print_string
call read_int
mov [choixCalcul], eax
cmp eax,1 ;compare eax à 1
jz bloc_addition
cmp eax,2 ;sinon compare eax à 2
jz bloc_soustraction
cmp eax,3 ;sinon compare eax à 3
jz bloc_multiplication
cmp eax,4 ;sinon compare eax à 4
jz bloc_division
jmp fin_programme ;sinon passe a la fin
bloc_addition:
mov eax,[num1]
call print_int
mov eax,plus
call print_string
mov eax,[num2]
call print_int
mov eax,egal
call print_string
mov eax,[num1]
add eax,[num2]
call print_int
call print_nl
jmp fin_programme
bloc_soustraction:
mov eax,[num1]
call print_int
mov eax,moins
call print_string
mov eax,[num2]
call print_int
mov eax,egal
call print_string
call print_nl
jmp fin_programme
bloc_multiplication:
mov eax,[num1]
call print_int
mov eax,fois
call print_string
mov eax,[num2]
call print_int
mov eax,egal
call print_string
call print_nl
jmp fin_programme
bloc_division:
mov eax,[num1]
call print_int
mov eax,divise
call print_string
mov eax,[num2]
call print_int
mov eax,egal
call print_string
call print_nl
jmp fin_programme
fin_programme:
popa
mov eax, 0 ; return back to C
leave
ret |