کد برنامه به زبان Assembly
include io.h
cr EQU 0dh ;carriage return character
lf EQU 0ah ;linefeed character
stack SEGMENT stack
DW 100h DUP(?)
stack ENDS
data SEGMENT
prompt DB cr,lf,'sum of number''s digits.'
DB cr,lf,'Please enter number: ',0
number DB 40 DUP(?)
answer DB cr,lf,'The result is: '
sum DB 6 DUP(?)
DB cr,lf,0
data ENDS
code SEGMENT
ASSUME cs:code,ds:data
start: mov ax,SEG data ;load data segment
mov ds,ax
print: output prompt
inputs number,40
atoi number
mov cx,10
mov bx,0 ;sum
while_loop:
div cx
add bx,ah
add al,0
jnz while_loop
mov ax,bx
itoa sum,ax
output answer
quit: mov al, 0 ;return code 0
mov ah, 4ch ;DOS function to return
int 21h ;interupt for DOS services
Code ENDS
END start
نمونه اجرایی از این برنامه:
درباره Assembly را در ادامه مطلب ببینید...