因此,Im将作此限定,说Im new to NRM, and I mread the 。 教学。
我把32比特80x86作为我的指令集(我认为......)在北纬度地区汇编成册。
我的方案的目的是从中宣读的插图中删除任何不必要的空间。 因此,护堤一开始的所有空间,以及一字之间任何双重或更大的空间。
我的方案几乎是用一个单一、无证件的特征完成的,这种特征对我都造成了影响。 如果我有两张拖车空间和一个拖车空间的字眼,我的节目将吃第二字的单一拖车空间。 但是,通常只出现两条空间一线的一审。
Here s my make file:
mstrebl : asm_io.inc asm_io.o driver.o mstrebl.o
gcc -o mstrebl -m32 asm_io.o driver.o mstrebl.o
driver.o : driver.c
gcc -c driver.c -m32
mstrebl.o: mstrebl.asm
nasm -f elf32 mstrebl.asm
这是一项称为ASM-的C方案。 教学课程
int main()
{
int ret_status;
ret_status = asm_main();
return ret_status;
}
这里是我的阿盟档案。
%include "asm_io.inc"
LF equ 0Ah
segment .data
name_prompt DB Please enter a string to be trimmed: ,0
out_msg DB The trimmed string is: ,0
segment .bss
in_name resb 80
segment .text
global asm_main
asm_main:
enter 0,0 ; setup routine
pusha
restart:
mov eax, name_prompt ; print prompt
call print_string
mov ebx, in_name
;for counting the number of digits
rd_loop:
call read_char ; read in the string
mov [ebx], al
inc ebx
cmp al, LF
jne rd_loop
dec ebx ; put in null terminator
mov byte [ebx], 0
call print_nl ; print output msg
mov eax, out_msg
call print_string
mov ebx, in_name ; EBX := address of in_name
push in_name
call strebl ;this pushes the string onto EAX, destroying old data.
call print_string
add esp, 4
Finished:
call print_nl
call print_nl
popa
mov eax, 0 ; return back to C
leave
ret
; subprogram get_int
; Parameters (in order pushed on stack)
;
;Address of the first character in a string (at [ebp + 8])
; Notes:
; There are no data shifts on the stack, only for the address
; of the array, as such, esp is not changed or shifted.
;
; Note, this destroys the contents of EAX.
; Note, this destroys the contents of CL.
;SUDO CODE!
;j = first address of the string
;if(*char == )
; return *char
;while((*char + i) == )
; i += 1
;
;
;while((*char + i != ))
;{
; if((*char + i) == )
; return *char
;
; (*char + j) = (*char + i)
; j += 1;
;}
;
;jump to original while
segment .data
temp db 0
segment .text
strebl:
push EBP
mov EBP, ESP
mov EAX, [EBP + 8] ; I
mov EBP, [EAX] ; J
First_while:
cmp byte [EAX], 0
je End_strebl
cmp byte[EAX], ;or 32 if i need to change it
jne Second_While
inc EAX ; i
jmp First_while
Second_While:
cmp byte [EAX], 0
je End_strebl
cmp byte[EAX],
je Second_While_helper
;*EBX = *EAX
mov ECX, [EAX]
mov [EBX], ECX
inc EAX ; increment I and J at the same time
inc EBX
jmp Second_While
Second_While_helper:
inc EAX
inc EBX
helper_loop:
cmp byte[EAX],
jne Second_While
inc EAX
jmp helper_loop
End_strebl:
cmp EAX, EBX
jz done_strebl
mov byte[EBX],
done_strebl:
mov EAX, [ESP + 8]
pop EBP
ret