├── .gitattributes ├── .gitignore ├── Homework1.docx ├── Homework2.docx ├── Homework2.pdf ├── Prentice.Hall.Structured.Computer.Organization.6th.Edition.0132916525 (1).pdf ├── Prentice.Hall.Structured.Computer.Organization.6th.Edition.0132916525.pdf ├── Structured Computer Organization, 6th Edition.pdf ├── lab0 ├── Debug │ ├── lab0.exe │ ├── lab0.ilk │ └── lab0.pdb ├── lab0-testing.c ├── lab0.c ├── lab0.sdf ├── lab0.sln ├── lab0.v11.suo └── lab0 │ ├── Debug │ ├── CL.read.1.tlog │ ├── CL.write.1.tlog │ ├── cl.command.1.tlog │ ├── lab0-testing.obj │ ├── lab0.lastbuildstate │ ├── lab0.log │ ├── lab0.obj │ ├── link-cvtres.read.1.tlog │ ├── link-cvtres.write.1.tlog │ ├── link-rc.read.1.tlog │ ├── link-rc.write.1.tlog │ ├── link.command.1.tlog │ ├── link.read.1.tlog │ ├── link.write.1.tlog │ ├── vc110.idb │ └── vc110.pdb │ ├── lab0.vcxproj │ └── lab0.vcxproj.filters ├── lab1 ├── Debug │ ├── CL.read.1.tlog │ ├── CL.write.1.tlog │ ├── cl.command.1.tlog │ ├── lab1-tests.obj │ ├── lab1.Build.CppClean.log │ ├── lab1.exe │ ├── lab1.ilk │ ├── lab1.lastbuildstate │ ├── lab1.log │ ├── lab1.obj │ ├── lab1.pdb │ ├── link-cvtres.read.1.tlog │ ├── link-cvtres.write.1.tlog │ ├── link-rc.read.1.tlog │ ├── link-rc.write.1.tlog │ ├── link.4236-cvtres.read.1.tlog │ ├── link.4236-cvtres.write.1.tlog │ ├── link.4236-rc.read.1.tlog │ ├── link.4236-rc.write.1.tlog │ ├── link.4236.read.1.tlog │ ├── link.4236.write.1.tlog │ ├── link.command.1.tlog │ ├── link.read.1.tlog │ ├── link.write.1.tlog │ ├── vc110.idb │ └── vc110.pdb ├── lab1-tests.c ├── lab1.c ├── lab1.sdf ├── lab1.sln ├── lab1.v11.suo ├── lab1.vcxproj └── lab1.vcxproj.filters └── lab2 ├── Debug ├── CL.read.1.tlog ├── CL.write.1.tlog ├── Michaelslab2.obj ├── cl.command.1.tlog ├── lab2-test.obj ├── lab2.Build.CppClean.log ├── lab2.exe ├── lab2.ilk ├── lab2.lastbuildstate ├── lab2.log ├── lab2.obj ├── lab2.pdb ├── lab2.tlog │ ├── CL.read.1.tlog │ ├── CL.write.1.tlog │ ├── cl.command.1.tlog │ ├── lab2.lastbuildstate │ ├── link.command.1.tlog │ ├── link.read.1.tlog │ └── link.write.1.tlog ├── link-cvtres.read.1.tlog ├── link-cvtres.write.1.tlog ├── link-rc.read.1.tlog ├── link-rc.write.1.tlog ├── link.command.1.tlog ├── link.read.1.tlog ├── link.write.1.tlog ├── vc110.idb ├── vc110.pdb ├── vc120.idb └── vc120.pdb ├── lab2-test.cpp ├── lab2.cpp ├── lab2.sdf ├── lab2.sln ├── lab2.v11.suo ├── lab2.v12.suo ├── lab2.vcxproj └── lab2.vcxproj.filters /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear on external disk 35 | .Spotlight-V100 36 | .Trashes 37 | 38 | # Directories potentially created on remote AFP share 39 | .AppleDB 40 | .AppleDesktop 41 | Network Trash Folder 42 | Temporary Items 43 | .apdisk 44 | -------------------------------------------------------------------------------- /Homework1.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/Homework1.docx -------------------------------------------------------------------------------- /Homework2.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/Homework2.docx -------------------------------------------------------------------------------- /Homework2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/Homework2.pdf -------------------------------------------------------------------------------- /Prentice.Hall.Structured.Computer.Organization.6th.Edition.0132916525 (1).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/Prentice.Hall.Structured.Computer.Organization.6th.Edition.0132916525 (1).pdf -------------------------------------------------------------------------------- /Prentice.Hall.Structured.Computer.Organization.6th.Edition.0132916525.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/Prentice.Hall.Structured.Computer.Organization.6th.Edition.0132916525.pdf -------------------------------------------------------------------------------- /Structured Computer Organization, 6th Edition.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/Structured Computer Organization, 6th Edition.pdf -------------------------------------------------------------------------------- /lab0/Debug/lab0.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab0/Debug/lab0.exe -------------------------------------------------------------------------------- /lab0/Debug/lab0.ilk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab0/Debug/lab0.ilk -------------------------------------------------------------------------------- /lab0/Debug/lab0.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab0/Debug/lab0.pdb -------------------------------------------------------------------------------- /lab0/lab0-testing.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | extern void lab0(int a, int b, int c, int *result); 6 | 7 | extern char *yourName; 8 | extern char *yourStudentID; 9 | static void testcode(); 10 | 11 | int main(void) 12 | { 13 | testcode(); 14 | return 0; 15 | } 16 | 17 | static void testcode (void) 18 | { 19 | int *result; 20 | 21 | printf ("ICS 51 Lab 0 \nName: %s\nStudentID: %s\n\n", 22 | yourName, yourStudentID); 23 | 24 | /* Once you are done implementing the function, activate one or more of 25 | the following test sequences. 26 | Procedure to activate a single test sequence: 27 | replace 28 | #define TEST2 0 29 | with 30 | #define TEST2 1 31 | You can similarly activate TEST1 and TEST3 32 | */ 33 | 34 | #define TEST1 1 35 | #define TEST2 1 36 | #define TEST3 1 37 | 38 | #if TEST1 39 | result = (int*) malloc(sizeof(int)); 40 | lab0(100,240,3,result); 41 | printf( "Input = %d, %d, %d, Output = %d\n", 100, 240, 3, *result ); 42 | free(result); 43 | #endif 44 | 45 | #if TEST2 46 | result = (int*) malloc(sizeof(int)); 47 | lab0(4,2,7,result); 48 | printf( "Input = %d, %d, %d, Output = %d\n", 4, 2, 7, *result ); 49 | free(result); 50 | #endif 51 | 52 | #if TEST3 53 | result = (int*) malloc(sizeof(int)); 54 | lab0(3,3,3,result); 55 | printf( "Input = %d, %d, %d, Output = %d\n", 3, 3, 3, *result ); 56 | free(result); 57 | #endif 58 | 59 | printf( "\nHit enter to quit" ); 60 | getchar(); 61 | } 62 | -------------------------------------------------------------------------------- /lab0/lab0.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* 5 | You are given three integer numbers. You need to add the smallest number to 6 | the largest number and multiply the resulting sum by two. 7 | 8 | Implementation details: 9 | The three integer numbers are stored in registers eax, ebx, and ecx. You need 10 | to store the answer into register edx. 11 | 12 | IMPORTANT comments: 13 | (i) To test your code see the "testcode" function in lab0-testing.c 14 | (ii) Write your assembly code only in the marked block. 15 | (iii) DO NOT write any code outside the marked block. 16 | (iv) You are not allowed to use any version of the MULTIPLY instruction! 17 | */ 18 | 19 | char *yourName = "Ford Tang"; 20 | char *yourStudentID = "46564602"; 21 | 22 | /* You are supposed to implement the body of this function */ 23 | 24 | void lab0( int a, int b, int c, int *result ) 25 | { 26 | __asm 27 | { 28 | mov esi, result 29 | push eax 30 | push ebx 31 | push ecx 32 | push edx 33 | 34 | mov eax, a 35 | mov ebx, b 36 | mov ecx, c 37 | 38 | // YOUR CODE STARTS HERE 39 | 40 | /* 41 | To sort 3 numbers, we use the following algorithm: 42 | if a < b: 43 | swap a, b 44 | if a < c: 45 | swap a, c 46 | if b < c 47 | swap b, c 48 | */ 49 | cmp eax, ebx // if eax < ebx 50 | jge L1 51 | mov edx, eax // swap eax, ebx 52 | mov eax, ebx 53 | mov ebx, edx 54 | L1: 55 | cmp eax, ecx // if eax < ecx 56 | jge L2 57 | mov edx, eax // swap eax, ecx 58 | mov eax, ecx 59 | mov ecx, edx 60 | L2: 61 | cmp ebx, ecx // if ebx < ecx 62 | jge L3 63 | mov edx, ebx // swap ebx, ecx 64 | mov ebx, ecx 65 | mov ecx, edx 66 | L3: 67 | add eax, ecx 68 | sal eax, 1 // eax = eax * 2 69 | mov edx, eax 70 | 71 | // YOUR CODE ENDS HERE 72 | 73 | END: 74 | mov [esi][0], edx 75 | pop edx 76 | pop ecx 77 | pop ebx 78 | pop eax 79 | } 80 | return; 81 | 82 | } 83 | -------------------------------------------------------------------------------- /lab0/lab0.sdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab0/lab0.sdf -------------------------------------------------------------------------------- /lab0/lab0.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lab0", "lab0\lab0.vcxproj", "{06DECD8D-3F3D-4B5C-8EC4-9D4677FBA4C6}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {06DECD8D-3F3D-4B5C-8EC4-9D4677FBA4C6}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {06DECD8D-3F3D-4B5C-8EC4-9D4677FBA4C6}.Debug|Win32.Build.0 = Debug|Win32 14 | {06DECD8D-3F3D-4B5C-8EC4-9D4677FBA4C6}.Release|Win32.ActiveCfg = Release|Win32 15 | {06DECD8D-3F3D-4B5C-8EC4-9D4677FBA4C6}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /lab0/lab0.v11.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab0/lab0.v11.suo -------------------------------------------------------------------------------- /lab0/lab0/Debug/CL.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab0/lab0/Debug/CL.read.1.tlog -------------------------------------------------------------------------------- /lab0/lab0/Debug/CL.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab0/lab0/Debug/CL.write.1.tlog -------------------------------------------------------------------------------- /lab0/lab0/Debug/cl.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab0/lab0/Debug/cl.command.1.tlog -------------------------------------------------------------------------------- /lab0/lab0/Debug/lab0-testing.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab0/lab0/Debug/lab0-testing.obj -------------------------------------------------------------------------------- /lab0/lab0/Debug/lab0.lastbuildstate: -------------------------------------------------------------------------------- 1 | #v4.0:v110:false 2 | Debug|Win32|C:\Users\FordT1\Desktop\lab0\| 3 | -------------------------------------------------------------------------------- /lab0/lab0/Debug/lab0.log: -------------------------------------------------------------------------------- 1 | Build started 1/14/2014 10:39:41 AM. 2 | 1>Project "C:\Users\FordT1\Desktop\lab0\lab0\lab0.vcxproj" on node 2 (Build target(s)). 3 | 1>ClCompile: 4 | C:\Program Files\Microsoft Visual Studio 11.0\VC\bin\CL.exe /c /ZI /nologo /W3 /WX- /sdl /Od /Oy- /D WIN32 /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Debug\\" /Fd"Debug\vc110.pdb" /Gd /TC /analyze- /errorReport:prompt "..\lab0-testing.c" 5 | lab0-testing.c 6 | 1>c:\users\fordt1\desktop\lab0\lab0-testing.c(39): warning C4013: 'malloc' undefined; assuming extern returning int 7 | 1>c:\users\fordt1\desktop\lab0\lab0-testing.c(42): warning C4013: 'free' undefined; assuming extern returning int 8 | Link: 9 | C:\Program Files\Microsoft Visual Studio 11.0\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:"C:\Users\FordT1\Desktop\lab0\Debug\lab0.exe" /INCREMENTAL /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:\Users\FordT1\Desktop\lab0\Debug\lab0.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\Users\FordT1\Desktop\lab0\Debug\lab0.lib" /MACHINE:X86 "Debug\lab0-testing.obj" 10 | Debug\lab0.obj 11 | lab0.vcxproj -> C:\Users\FordT1\Desktop\lab0\Debug\lab0.exe 12 | 1>Done Building Project "C:\Users\FordT1\Desktop\lab0\lab0\lab0.vcxproj" (Build target(s)). 13 | 14 | Build succeeded. 15 | 16 | Time Elapsed 00:00:00.79 17 | -------------------------------------------------------------------------------- /lab0/lab0/Debug/lab0.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab0/lab0/Debug/lab0.obj -------------------------------------------------------------------------------- /lab0/lab0/Debug/link-cvtres.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab0/lab0/Debug/link-cvtres.read.1.tlog -------------------------------------------------------------------------------- /lab0/lab0/Debug/link-cvtres.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab0/lab0/Debug/link-cvtres.write.1.tlog -------------------------------------------------------------------------------- /lab0/lab0/Debug/link-rc.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab0/lab0/Debug/link-rc.read.1.tlog -------------------------------------------------------------------------------- /lab0/lab0/Debug/link-rc.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab0/lab0/Debug/link-rc.write.1.tlog -------------------------------------------------------------------------------- /lab0/lab0/Debug/link.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab0/lab0/Debug/link.command.1.tlog -------------------------------------------------------------------------------- /lab0/lab0/Debug/link.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab0/lab0/Debug/link.read.1.tlog -------------------------------------------------------------------------------- /lab0/lab0/Debug/link.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab0/lab0/Debug/link.write.1.tlog -------------------------------------------------------------------------------- /lab0/lab0/Debug/vc110.idb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab0/lab0/Debug/vc110.idb -------------------------------------------------------------------------------- /lab0/lab0/Debug/vc110.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab0/lab0/Debug/vc110.pdb -------------------------------------------------------------------------------- /lab0/lab0/lab0.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {06DECD8D-3F3D-4B5C-8EC4-9D4677FBA4C6} 15 | Win32Proj 16 | lab0 17 | 18 | 19 | 20 | Application 21 | true 22 | v110 23 | Unicode 24 | 25 | 26 | Application 27 | false 28 | v110 29 | true 30 | Unicode 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | true 44 | 45 | 46 | false 47 | 48 | 49 | 50 | 51 | 52 | Level3 53 | Disabled 54 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 55 | true 56 | 57 | 58 | Console 59 | true 60 | 61 | 62 | 63 | 64 | Level3 65 | 66 | 67 | MaxSpeed 68 | true 69 | true 70 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 71 | true 72 | 73 | 74 | Console 75 | true 76 | true 77 | true 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /lab0/lab0/lab0.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | -------------------------------------------------------------------------------- /lab1/Debug/CL.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab1/Debug/CL.read.1.tlog -------------------------------------------------------------------------------- /lab1/Debug/CL.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab1/Debug/CL.write.1.tlog -------------------------------------------------------------------------------- /lab1/Debug/cl.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab1/Debug/cl.command.1.tlog -------------------------------------------------------------------------------- /lab1/Debug/lab1-tests.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab1/Debug/lab1-tests.obj -------------------------------------------------------------------------------- /lab1/Debug/lab1.Build.CppClean.log: -------------------------------------------------------------------------------- 1 | C:\USERS\DALI\DROPBOX\ICS51\LABS\LAB1_WORKSPACE\LAB1\DEBUG\LAB1.OBJ 2 | C:\USERS\DALI\DROPBOX\ICS51\LABS\LAB1_WORKSPACE\LAB1\DEBUG\LAB1-TESTS.OBJ 3 | C:\USERS\DALI\DROPBOX\ICS51\LABS\LAB1_WORKSPACE\LAB1\DEBUG\VC110.PDB 4 | C:\USERS\DALI\DROPBOX\ICS51\LABS\LAB1\DEBUG\LAB1-TESTS.OBJ 5 | C:\USERS\DALI\DROPBOX\ICS51\LABS\LAB1\DEBUG\LAB1.OBJ 6 | C:\USERS\DALI\DROPBOX\ICS51\LABS\LAB1\DEBUG\VC110.PDB 7 | C:\USERS\DALI\DROPBOX\ICS51\LABS\LAB1_WORKSPACE\LAB1\DEBUG\LAB1.ILK 8 | C:\USERS\DALI\DROPBOX\ICS51\LABS\LAB1_WORKSPACE\LAB1\DEBUG\LAB1.EXE 9 | C:\USERS\DALI\DROPBOX\ICS51\LABS\LAB1_WORKSPACE\LAB1\DEBUG\LAB1.PDB 10 | C:\USERS\DALI\DROPBOX\ICS51\LABS\LAB1\DEBUG\LAB1.ILK 11 | C:\USERS\DALI\DROPBOX\ICS51\LABS\LAB1\DEBUG\LAB1.EXE 12 | C:\USERS\DALI\DROPBOX\ICS51\LABS\LAB1\DEBUG\LAB1.PDB 13 | C:\Users\Dali\Dropbox\ics51\labs\lab1\Debug\lab1-tests.obj 14 | C:\Users\Dali\Dropbox\ics51\labs\lab1\Debug\lab1.obj 15 | C:\Users\Dali\Dropbox\ics51\labs\lab1\Debug\lab1.ilk 16 | C:\Users\Dali\Dropbox\ics51\labs\lab1\Debug\cl.command.1.tlog 17 | C:\Users\Dali\Dropbox\ics51\labs\lab1\Debug\CL.read.1.tlog 18 | C:\Users\Dali\Dropbox\ics51\labs\lab1\Debug\CL.write.1.tlog 19 | C:\Users\Dali\Dropbox\ics51\labs\lab1\Debug\link-cvtres.read.1.tlog 20 | C:\Users\Dali\Dropbox\ics51\labs\lab1\Debug\link-cvtres.write.1.tlog 21 | C:\Users\Dali\Dropbox\ics51\labs\lab1\Debug\link-rc.read.1.tlog 22 | C:\Users\Dali\Dropbox\ics51\labs\lab1\Debug\link-rc.write.1.tlog 23 | C:\Users\Dali\Dropbox\ics51\labs\lab1\Debug\link.4664-cvtres.read.1.tlog 24 | C:\Users\Dali\Dropbox\ics51\labs\lab1\Debug\link.4664-cvtres.write.1.tlog 25 | C:\Users\Dali\Dropbox\ics51\labs\lab1\Debug\link.4664-rc.read.1.tlog 26 | C:\Users\Dali\Dropbox\ics51\labs\lab1\Debug\link.4664-rc.write.1.tlog 27 | C:\Users\Dali\Dropbox\ics51\labs\lab1\Debug\link.4664.read.1.tlog 28 | C:\Users\Dali\Dropbox\ics51\labs\lab1\Debug\link.4664.write.1.tlog 29 | C:\Users\Dali\Dropbox\ics51\labs\lab1\Debug\link.command.1.tlog 30 | C:\Users\Dali\Dropbox\ics51\labs\lab1\Debug\link.read.1.tlog 31 | C:\Users\Dali\Dropbox\ics51\labs\lab1\Debug\link.write.1.tlog 32 | C:\Users\Dali\Dropbox\ics51\labs\lab1\Debug\vc110.idb 33 | C:\Users\Dali\Dropbox\ics51\labs\lab1\Debug\lab1.pdb 34 | C:\Users\Dali\Dropbox\ics51\labs\lab1\Debug\vc110.pdb 35 | C:\Users\Dali\Dropbox\ics51\labs\lab1\Debug\lab1.exe 36 | -------------------------------------------------------------------------------- /lab1/Debug/lab1.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab1/Debug/lab1.exe -------------------------------------------------------------------------------- /lab1/Debug/lab1.ilk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab1/Debug/lab1.ilk -------------------------------------------------------------------------------- /lab1/Debug/lab1.lastbuildstate: -------------------------------------------------------------------------------- 1 | #v4.0:v110:false 2 | Debug|Win32|C:\Users\rbchou\Desktop\lab1 (1)\lab1\| 3 | -------------------------------------------------------------------------------- /lab1/Debug/lab1.log: -------------------------------------------------------------------------------- 1 | Build started 2/3/2014 7:10:38 PM. 2 | 1>Project "C:\Users\rbchou\Desktop\lab1 (1)\lab1\lab1.vcxproj" on node 2 (Build target(s)). 3 | 1>ClCompile: 4 | C:\Program Files\Microsoft Visual Studio 11.0\VC\bin\CL.exe /c /ZI /nologo /W3 /WX- /Od /Oy- /D WIN32 /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Debug\\" /Fd"Debug\vc110.pdb" /Gd /TC /analyze- /errorReport:prompt lab1.c 5 | lab1.c 6 | Link: 7 | C:\Program Files\Microsoft Visual Studio 11.0\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:"C:\Users\rbchou\Desktop\lab1 (1)\lab1\Debug\lab1.exe" /INCREMENTAL /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:\Users\rbchou\Desktop\lab1 (1)\lab1\Debug\lab1.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\Users\rbchou\Desktop\lab1 (1)\lab1\Debug\lab1.lib" /MACHINE:X86 "Debug\lab1-tests.obj" 8 | Debug\lab1.obj 9 | lab1.vcxproj -> C:\Users\rbchou\Desktop\lab1 (1)\lab1\Debug\lab1.exe 10 | 1>Done Building Project "C:\Users\rbchou\Desktop\lab1 (1)\lab1\lab1.vcxproj" (Build target(s)). 11 | 12 | Build succeeded. 13 | 14 | Time Elapsed 00:00:00.63 15 | -------------------------------------------------------------------------------- /lab1/Debug/lab1.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab1/Debug/lab1.obj -------------------------------------------------------------------------------- /lab1/Debug/lab1.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab1/Debug/lab1.pdb -------------------------------------------------------------------------------- /lab1/Debug/link-cvtres.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab1/Debug/link-cvtres.read.1.tlog -------------------------------------------------------------------------------- /lab1/Debug/link-cvtres.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab1/Debug/link-cvtres.write.1.tlog -------------------------------------------------------------------------------- /lab1/Debug/link-rc.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab1/Debug/link-rc.read.1.tlog -------------------------------------------------------------------------------- /lab1/Debug/link-rc.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab1/Debug/link-rc.write.1.tlog -------------------------------------------------------------------------------- /lab1/Debug/link.4236-cvtres.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab1/Debug/link.4236-cvtres.read.1.tlog -------------------------------------------------------------------------------- /lab1/Debug/link.4236-cvtres.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab1/Debug/link.4236-cvtres.write.1.tlog -------------------------------------------------------------------------------- /lab1/Debug/link.4236-rc.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab1/Debug/link.4236-rc.read.1.tlog -------------------------------------------------------------------------------- /lab1/Debug/link.4236-rc.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab1/Debug/link.4236-rc.write.1.tlog -------------------------------------------------------------------------------- /lab1/Debug/link.4236.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab1/Debug/link.4236.read.1.tlog -------------------------------------------------------------------------------- /lab1/Debug/link.4236.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab1/Debug/link.4236.write.1.tlog -------------------------------------------------------------------------------- /lab1/Debug/link.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab1/Debug/link.command.1.tlog -------------------------------------------------------------------------------- /lab1/Debug/link.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab1/Debug/link.read.1.tlog -------------------------------------------------------------------------------- /lab1/Debug/link.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab1/Debug/link.write.1.tlog -------------------------------------------------------------------------------- /lab1/Debug/vc110.idb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab1/Debug/vc110.idb -------------------------------------------------------------------------------- /lab1/Debug/vc110.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab1/Debug/vc110.pdb -------------------------------------------------------------------------------- /lab1/lab1-tests.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | //when you want to test one of the parts of the assignment, just change the 0 into a 1 for 8 | //the constant corresponding to that part 9 | #define POSITIVE_SUM 1 10 | #define TOUPPER 1 11 | #define ISPRIME 1 12 | 13 | extern char *yourName; 14 | extern char *studentID; 15 | 16 | extern int positiveSum(int *str, int len); 17 | extern void toUpper(char *str); 18 | extern int isPrime(unsigned int x); 19 | 20 | void testPositiveSum(int *Arr, int len); 21 | void checkUpper(char *str); 22 | int checkPrime(unsigned int x); 23 | 24 | void main() 25 | { 26 | int i; 27 | 28 | #if POSITIVE_SUM 29 | int * Arr; 30 | #endif 31 | 32 | #if TOUPPER 33 | char *test2[5]={"Hello, World!", "ABCDEFG", "", "12345", "~!@#$"}; 34 | #endif 35 | 36 | #if ISPRIME 37 | unsigned test3[10]={0, 1, 2, 3, 10, 121, 97, 169, 3571, 3590989}; 38 | #endif 39 | 40 | printf("ICS 51 Summer 2013 - Lab 2\n\n"); 41 | printf("Name: %s\n", yourName); 42 | printf("Student ID: %s\n\n", studentID); 43 | 44 | #if POSITIVE_SUM 45 | Arr = (int*)malloc(sizeof(int)); 46 | Arr[0] = 0; 47 | testPositiveSum(Arr, 1); 48 | free(Arr); 49 | 50 | Arr = (int*)malloc(sizeof(int)*5); 51 | for(i = 0; i < 5; i++) { 52 | Arr[i] = -1; 53 | } 54 | testPositiveSum(Arr, 5); 55 | 56 | for(i = 0; i < 5; i++) { 57 | Arr[i] = 1; 58 | } 59 | testPositiveSum(Arr, 5); 60 | 61 | for(i = 0; i < 5; i++) { 62 | Arr[i] = i * 5 - 10; 63 | } 64 | testPositiveSum(Arr, 5); 65 | 66 | free(Arr); 67 | #endif 68 | 69 | #if TOUPPER 70 | for(i = 0; i < 5; i++) { 71 | checkUpper(test2[i]); 72 | } 73 | #endif 74 | 75 | #if ISPRIME 76 | for(i = 0; i < 10; i++) { 77 | printf("%u: %u\n", test3[i], isPrime(test3[i])); 78 | if(checkPrime(test3[i])) { 79 | printf("%u is a prime number. %u", test3[i]); 80 | if(isPrime(test3[i])) { 81 | printf(" And your function agrees.\n\n"); 82 | } else { 83 | printf(" But your function is WRONG******XXXXXX******.\n\n"); 84 | } 85 | } else { 86 | printf("%u is not a prime number.", test3[i]); 87 | if(isPrime(test3[i])) { 88 | printf(" But your function is WRONG******XXXXXX******.\n\n"); 89 | } else { 90 | printf(" And your function agrees.\n\n"); 91 | } 92 | } 93 | } 94 | #endif 95 | 96 | system("PAUSE"); 97 | } 98 | 99 | #if POSITIVE_SUM 100 | void testPositiveSum(int *Arr, int len) { 101 | int i; 102 | int correct = 0; 103 | int result; 104 | 105 | if (len <= 0) return; 106 | 107 | printf("Testing array: "); 108 | printf("%d", Arr[0]); 109 | 110 | for (i = 1; i < len; i++) { 111 | printf(", %d", Arr[i]); 112 | } 113 | printf(".\n"); 114 | 115 | for(i = 0; i < len; i++) { 116 | if(Arr[i] > 0) { 117 | correct += Arr[i]; 118 | } 119 | } 120 | 121 | result = positiveSum(Arr, len); 122 | 123 | if (correct == result) { 124 | printf("Your answer is %d, and it is correct.\n", result); 125 | } else { 126 | printf("Your answer is %d, but the correct one should be %d\n", result, correct); 127 | } 128 | } 129 | #endif 130 | #if TOUPPER 131 | void checkUpper(char *str){ 132 | 133 | char buff[30], *p; 134 | 135 | if(str==NULL) { 136 | return; 137 | } 138 | 139 | strcpy_s(buff, 29, str); 140 | 141 | printf("Original string: %s\n", buff); 142 | toUpper(buff); 143 | printf("Called toUpper: %s\n", buff); 144 | 145 | for (p=buff; *p; p++) { 146 | if(*p != toupper(*p)) { 147 | printf("***ERROR FOUND***.\n"); 148 | printf("***ERROR FOUND***.\n"); 149 | printf("***ERROR FOUND***.\n\n"); 150 | } 151 | } 152 | printf("conversion is correct.\n\n"); 153 | } 154 | #endif 155 | 156 | #if ISPRIME 157 | int checkPrime(unsigned int x) { 158 | unsigned int y, i; 159 | 160 | if(x==0 || x==1) { 161 | return 0; 162 | } 163 | 164 | if(x==2) { 165 | return 1; 166 | } 167 | 168 | if((x & 0x01) == 0) { 169 | return 0; 170 | } 171 | 172 | y = (unsigned)(sqrt((double)x)); 173 | for (i = 3; i <= y; i+=2){ 174 | if(x % i == 0) { 175 | return 0; 176 | } 177 | } 178 | 179 | return 1; 180 | } 181 | #endif 182 | -------------------------------------------------------------------------------- /lab1/lab1.c: -------------------------------------------------------------------------------- 1 | //ICS 51. Lab #1 2 | 3 | #include 4 | 5 | char * yourName = "Ford Tang"; 6 | char * studentID = "46564602"; 7 | /******************************************************************************* 8 | Part A. 9 | Inplement positiveSum function that calculates the sum of all the positive 10 | numbers in an integer array. The signature of positiveSum function is: 11 | 12 | int positiveSum( int *Arr, int len ); 13 | 14 | It has 2 arguments. int *Arr is a pointer, which points to the beginning of 15 | the array. int length is the length of the array. To return the result, you 16 | should store it in register EAX. Since all the registers are visible by the 17 | caller function, when we want to return something, we can just leave it in a 18 | register. The convetnion is to leave the return value in EAX. 19 | 20 | In an array, several integers are stored together, one after another. 21 | So if the first element in the array is at the address of 3064, the next 22 | element will be at 3068, and the next will be 3072. This is because each 23 | integer occupies 4 bytes of memory. 24 | 25 | Example: 26 | If we have an array of [1, 3, -5, 7], the sum should be 1 + 3 + 7 = 11. 27 | *******************************************************************************/ 28 | 29 | int positiveSum( int *Arr, int len ) { 30 | __asm{ 31 | PUSH EBX 32 | PUSH ECX 33 | PUSH EDX 34 | PUSH ESI 35 | PUSH EDI 36 | 37 | MOV EBX, Arr 38 | MOV ECX, len 39 | 40 | /* Your code begins below this line. */ 41 | MOV EAX, 0 //Clearing EAX so return is ready. 42 | MOV EDX, 0 //Moving zero ito EDX, Using EDX as counter and current index of array. 43 | 44 | CHECK: 45 | CMP EDX, ECX //Comparing current index of array to the total length of array. 46 | JG END //If current index is greater than total length of array, jump to END. 47 | CMP [EBX+EDX*4], 0 //Comparing value in current index against zero. 48 | JL SKIP //If current index value is less than zero, jump to SKIP. 49 | ADD EAX, [EBX+EDX*4] //Add current index value to EAX(return register). 50 | 51 | SKIP: 52 | ADD EDX, 1 //Add 1 to EDX(current index of array counter) 53 | JMP CHECK //Jump to CHECK to continue the loop. 54 | 55 | END: 56 | /* Your code ends above this line. */ 57 | 58 | POP EDI 59 | POP ESI 60 | POP EDX 61 | POP ECX 62 | POP EBX 63 | } 64 | } 65 | 66 | 67 | 68 | /******************************************************************************* 69 | Part B. 70 | Implement the toUpper function that converts lower-case letters in a string 71 | to upper-case. The function takes one parameter: char *string. string is a 72 | char type pointer, which points to the beginning of the string. Because C- 73 | style strings are terminated by a zero, we do not need to take the length of 74 | the string as another parameter. Please see hint 2 for more details. 75 | 76 | You should do the conversion in-place, which means you should change the 77 | characters in its original location. 78 | 79 | A few hints: 80 | 1. Only lower-case letters are converted. Punctuation marks should remain 81 | the same. 82 | 83 | 2. Here is how strings are stored in the memory: 84 | A string is an array of ASCII characters. So the string is actually an array 85 | of ASCII values. In C/C++, we use a char type pointer (char*) to denote the 86 | beginning of a string. The pointer points to the very first character of the 87 | string. How do we find the end? The end of a string represented by a 0. For 88 | example, "Hello" is stored as 72, 101, 108, 108, 111, 0. Zero (0) could be 89 | used as the terminating symbol, because all valid ASCII characters are non- 90 | zero. Note that "Hello" is actually 5 characters long, but it requires 6 91 | bytes of storage, including the terminating 0. 92 | 93 | 3. Changing a character is actually adjusting its ASCII value. Use Google 94 | to find an ASCII table and observe, what change is required to switch 95 | between upper and lower case. 96 | 97 | *******************************************************************************/ 98 | 99 | void toUpper(char *string) { 100 | __asm{ 101 | 102 | PUSH EAX 103 | PUSH EBX 104 | PUSH ECX 105 | PUSH EDX 106 | PUSH ESI 107 | PUSH EDI 108 | 109 | MOV EBX, string 110 | 111 | /* Your code begins below this line. */ 112 | MOV ECX, 0 //Moving zero into ECX, using ECX as the counter for current index in array. 113 | 114 | CHANGE: 115 | CMP [EBX+ECX], 0 //Comparing current index value to 0. 116 | JE END //Jump if current index value is less than zero (End of string). 117 | CMP [EBX+ECX], 97 //Comparing current index value to the starting value of the lower-case alphabets in the ASCII table. 118 | JL SKIPCHAR //If current index value(character) is less than starting value for lower-case alphabets in ASCII table, jump to SKIPCHAR. 119 | CMP [EBX+ECX], 122 //Comparing current index value to the last value of the lower-case alphabets in the ASCII table. 120 | JG SKIPCHAR //If current index value(character) is greater than the last value for lower-case alphabets in the ASCII table, jump to SKIPCHAR. 121 | AND [EBX+ECX], 223 //AND current index value(character) to 11011111(binary), which will change lowercase letters to uppercase, will not change uppercase letters. 122 | 123 | SKIPCHAR: 124 | ADD ECX, 1 //Add 1 to ECX(counter for current array index) 125 | JMP CHANGE //Jump to CHANGE to continue loop. 126 | 127 | END: 128 | /* Your code ends above this line. */ 129 | 130 | POP EDI 131 | POP ESI 132 | POP EDX 133 | POP ECX 134 | POP EBX 135 | POP EAX 136 | 137 | } 138 | } 139 | 140 | /******************************************************************************* 141 | Part C. (Optional, will not be graded) 142 | Inplement isPrime function that tests if an integer is a prime number. The 143 | function takes an unsigned integer as parameter, and returns 1 if the 144 | integer is a prime number, and 0 otherwise. For this part, you should learn 145 | to use the DIV instruction. 146 | 147 | Example: 148 | 149 | isPrime(2) returns 1 150 | isPrime(4) returns 0. 151 | 152 | Hint: What happens to your algorithm if x = 0? or x = 1? 153 | 154 | Bonus questions: (No extra credit) 155 | To test if x is a prime number or not, what is the minimum number of 156 | divisions you'll have to calculate? How many divisions are you calculating 157 | in your own implementation? How to make your program run faster? 158 | *******************************************************************************/ 159 | 160 | int isPrime(unsigned int x) { 161 | __asm{ 162 | 163 | PUSH EBX 164 | PUSH ECX 165 | PUSH EDX 166 | PUSH ESI 167 | PUSH EDI 168 | 169 | MOV EDI, x 170 | 171 | /* Your code begins below this line. */ 172 | CMP EDI, 2 //Comparing EDI with the value 2, checking to see if EDI is less than 2. 173 | JL NOTPRIME //Jump if EDI is less than 2 to NOTPRIME. 174 | CMP EDI, 2 //Comparing EDI with the value 2, if EDI is 2, number is prime. 175 | JE PRIME //Jump if EDI is equal to 2, jump to PRIME 176 | CMP EDI, 3 //Comparing EDI with the value 3, if EDI is 3, number is prime. 177 | JE PRIME //Jump if EDI is equal to 3, jump to PRIME 178 | MOV EAX, EDI //Moving EDI into EAX, using EAX to check for even number. 179 | AND EAX, 1 //AND EAX with 1, if result is 0, number is even. 180 | CMP EAX, 0 //Comparing EAX with 0, if EAX is zero, the original number was even and not prime. 181 | JE NOTPRIME //If EAX was zero, jump to NOTPRIME. 182 | MOV EBX, 3 //Move 3 into EBX, readying EBX to be the divisor of EDI 183 | 184 | CHECKPRIME: 185 | MOV EDX, 0 186 | MOV EAX, EDI //Moving EDI into EAX so EAX can be divided by EBX 187 | DIV EBX //Divide EAX by EBX, the remainder goes to EDX 188 | CMP EDX, 0 //Comparing EDX to zero, if value is zero, the number divided successfully and is not prime. 189 | JE NOTPRIME //If EDX(remainder) is zero, number was divided successfully and the number is not prime. Jump to NOTPRIME. 190 | ADD EBX, 2 //ADD 2 to EBX(new divisor value) 191 | MOV EAX, EBX //Move EBX into EAX, checking to see if divisor is less than the square root of the given number. 192 | MUL EAX //Multiplying EAX(divisor) by itself to see if is less than the given number. 193 | CMP EAX, EDI //Comparing EAX with EDI(given number). 194 | JG PRIME //If EAX is greater than the given number, than no number has been divided successfully into the given number, and the number is prime. Jump to PRIME. 195 | JMP CHECKPRIME //Jump back to CHECKPRIME to continue checking the given number. 196 | 197 | NOTPRIME: 198 | MOV EAX, 0 //Move zero into EAX, returning False for result. 199 | JMP END //Jump to END 200 | 201 | PRIME: 202 | MOV EAX, 1 //Move 1 into EAX, returning True for result. 203 | 204 | END: 205 | /* Your code ends above this line. */ 206 | 207 | POP EDI 208 | POP ESI 209 | POP EDX 210 | POP ECX 211 | POP EBX 212 | } 213 | } 214 | 215 | -------------------------------------------------------------------------------- /lab1/lab1.sdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab1/lab1.sdf -------------------------------------------------------------------------------- /lab1/lab1.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lab1", "lab1.vcxproj", "{3ACA683D-BDBB-4470-9004-25342D82B6BE}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {3ACA683D-BDBB-4470-9004-25342D82B6BE}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {3ACA683D-BDBB-4470-9004-25342D82B6BE}.Debug|Win32.Build.0 = Debug|Win32 14 | {3ACA683D-BDBB-4470-9004-25342D82B6BE}.Release|Win32.ActiveCfg = Release|Win32 15 | {3ACA683D-BDBB-4470-9004-25342D82B6BE}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /lab1/lab1.v11.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab1/lab1.v11.suo -------------------------------------------------------------------------------- /lab1/lab1.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {3ACA683D-BDBB-4470-9004-25342D82B6BE} 15 | Win32Proj 16 | lab1 17 | 18 | 19 | 20 | Application 21 | true 22 | v110 23 | Unicode 24 | 25 | 26 | Application 27 | false 28 | v110 29 | true 30 | Unicode 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | true 44 | 45 | 46 | false 47 | 48 | 49 | 50 | 51 | 52 | Level3 53 | Disabled 54 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 55 | 56 | 57 | Console 58 | true 59 | 60 | 61 | 62 | 63 | Level3 64 | 65 | 66 | MaxSpeed 67 | true 68 | true 69 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 70 | 71 | 72 | Console 73 | true 74 | true 75 | true 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /lab1/lab1.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | -------------------------------------------------------------------------------- /lab2/Debug/CL.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab2/Debug/CL.read.1.tlog -------------------------------------------------------------------------------- /lab2/Debug/CL.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab2/Debug/CL.write.1.tlog -------------------------------------------------------------------------------- /lab2/Debug/Michaelslab2.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab2/Debug/Michaelslab2.obj -------------------------------------------------------------------------------- /lab2/Debug/cl.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab2/Debug/cl.command.1.tlog -------------------------------------------------------------------------------- /lab2/Debug/lab2-test.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab2/Debug/lab2-test.obj -------------------------------------------------------------------------------- /lab2/Debug/lab2.Build.CppClean.log: -------------------------------------------------------------------------------- 1 | C:\USERS\DALI\DROPBOX\ICS51\LABS\LAB2\DEBUG\LAB2-TEST.OBJ 2 | C:\USERS\DALI\DROPBOX\ICS51\LABS\LAB2\DEBUG\VC110.PDB 3 | C:\USERS\DALI\DROPBOX\ICS51\LABS\LAB2\DEBUG\LAB2.OBJ 4 | C:\USERS\DALI\DROPBOX\ICS51\LABS\LAB2\DEBUG\LAB2.ILK 5 | C:\USERS\DALI\DROPBOX\ICS51\LABS\LAB2\DEBUG\LAB2.EXE 6 | C:\USERS\DALI\DROPBOX\ICS51\LABS\LAB2\DEBUG\LAB2.PDB 7 | C:\Users\Dali\Dropbox\ics51\labs\lab2\Debug\lab2-test.obj 8 | C:\Users\Dali\Dropbox\ics51\labs\lab2\Debug\lab2.obj 9 | C:\Users\Dali\Dropbox\ics51\labs\lab2\Debug\lab2.ilk 10 | C:\Users\Dali\Dropbox\ics51\labs\lab2\Debug\cl.command.1.tlog 11 | C:\Users\Dali\Dropbox\ics51\labs\lab2\Debug\CL.read.1.tlog 12 | C:\Users\Dali\Dropbox\ics51\labs\lab2\Debug\CL.write.1.tlog 13 | C:\Users\Dali\Dropbox\ics51\labs\lab2\Debug\link-cvtres.read.1.tlog 14 | C:\Users\Dali\Dropbox\ics51\labs\lab2\Debug\link-cvtres.write.1.tlog 15 | C:\Users\Dali\Dropbox\ics51\labs\lab2\Debug\link-rc.read.1.tlog 16 | C:\Users\Dali\Dropbox\ics51\labs\lab2\Debug\link-rc.write.1.tlog 17 | C:\Users\Dali\Dropbox\ics51\labs\lab2\Debug\link.11452-cvtres.read.1.tlog 18 | C:\Users\Dali\Dropbox\ics51\labs\lab2\Debug\link.11452-cvtres.write.1.tlog 19 | C:\Users\Dali\Dropbox\ics51\labs\lab2\Debug\link.11452-rc.read.1.tlog 20 | C:\Users\Dali\Dropbox\ics51\labs\lab2\Debug\link.11452-rc.write.1.tlog 21 | C:\Users\Dali\Dropbox\ics51\labs\lab2\Debug\link.11452.read.1.tlog 22 | C:\Users\Dali\Dropbox\ics51\labs\lab2\Debug\link.11452.write.1.tlog 23 | C:\Users\Dali\Dropbox\ics51\labs\lab2\Debug\link.command.1.tlog 24 | C:\Users\Dali\Dropbox\ics51\labs\lab2\Debug\link.read.1.tlog 25 | C:\Users\Dali\Dropbox\ics51\labs\lab2\Debug\link.write.1.tlog 26 | C:\Users\Dali\Dropbox\ics51\labs\lab2\Debug\vc110.idb 27 | C:\Users\Dali\Dropbox\ics51\labs\lab2\Debug\lab2.pdb 28 | C:\Users\Dali\Dropbox\ics51\labs\lab2\Debug\vc110.pdb 29 | C:\Users\Dali\Dropbox\ics51\labs\lab2\Debug\lab2.exe 30 | -------------------------------------------------------------------------------- /lab2/Debug/lab2.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab2/Debug/lab2.exe -------------------------------------------------------------------------------- /lab2/Debug/lab2.ilk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab2/Debug/lab2.ilk -------------------------------------------------------------------------------- /lab2/Debug/lab2.lastbuildstate: -------------------------------------------------------------------------------- 1 | #v4.0:v110:false 2 | Debug|Win32|C:\Users\FordT1\Desktop\lab2\| 3 | -------------------------------------------------------------------------------- /lab2/Debug/lab2.log: -------------------------------------------------------------------------------- 1 | Build started 3/7/2014 9:57:23 PM. 2 | 1>Project "C:\Users\Ford\Desktop\lab2\lab2.vcxproj" on node 2 (Build target(s)). 3 | 1>ClCompile: 4 | E:\Software\Microsoft Visual Studio 12.0\VC\bin\CL.exe /c /ZI /nologo /W3 /WX- /sdl /Od /Oy- /D WIN32 /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Debug\\" /Fd"Debug\vc120.pdb" /Gd /TP /analyze- /errorReport:prompt "lab2-test.cpp" 5 | lab2-test.cpp 6 | Link: 7 | E:\Software\Microsoft Visual Studio 12.0\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:"C:\Users\Ford\Desktop\lab2\Debug\lab2.exe" /INCREMENTAL /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:\Users\Ford\Desktop\lab2\Debug\lab2.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\Users\Ford\Desktop\lab2\Debug\lab2.lib" /MACHINE:X86 "Debug\lab2-test.obj" 8 | Debug\lab2.obj 9 | lab2.vcxproj -> C:\Users\Ford\Desktop\lab2\Debug\lab2.exe 10 | 1>Done Building Project "C:\Users\Ford\Desktop\lab2\lab2.vcxproj" (Build target(s)). 11 | 12 | Build succeeded. 13 | 14 | Time Elapsed 00:00:00.80 15 | -------------------------------------------------------------------------------- /lab2/Debug/lab2.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab2/Debug/lab2.obj -------------------------------------------------------------------------------- /lab2/Debug/lab2.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab2/Debug/lab2.pdb -------------------------------------------------------------------------------- /lab2/Debug/lab2.tlog/CL.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab2/Debug/lab2.tlog/CL.read.1.tlog -------------------------------------------------------------------------------- /lab2/Debug/lab2.tlog/CL.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab2/Debug/lab2.tlog/CL.write.1.tlog -------------------------------------------------------------------------------- /lab2/Debug/lab2.tlog/cl.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab2/Debug/lab2.tlog/cl.command.1.tlog -------------------------------------------------------------------------------- /lab2/Debug/lab2.tlog/lab2.lastbuildstate: -------------------------------------------------------------------------------- 1 | #TargetFrameworkVersion=v4.0:PlatformToolSet=v120:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit 2 | Debug|Win32|C:\Users\Ford\Desktop\lab2\| 3 | -------------------------------------------------------------------------------- /lab2/Debug/lab2.tlog/link.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab2/Debug/lab2.tlog/link.command.1.tlog -------------------------------------------------------------------------------- /lab2/Debug/lab2.tlog/link.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab2/Debug/lab2.tlog/link.read.1.tlog -------------------------------------------------------------------------------- /lab2/Debug/lab2.tlog/link.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab2/Debug/lab2.tlog/link.write.1.tlog -------------------------------------------------------------------------------- /lab2/Debug/link-cvtres.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab2/Debug/link-cvtres.read.1.tlog -------------------------------------------------------------------------------- /lab2/Debug/link-cvtres.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab2/Debug/link-cvtres.write.1.tlog -------------------------------------------------------------------------------- /lab2/Debug/link-rc.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab2/Debug/link-rc.read.1.tlog -------------------------------------------------------------------------------- /lab2/Debug/link-rc.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab2/Debug/link-rc.write.1.tlog -------------------------------------------------------------------------------- /lab2/Debug/link.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab2/Debug/link.command.1.tlog -------------------------------------------------------------------------------- /lab2/Debug/link.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab2/Debug/link.read.1.tlog -------------------------------------------------------------------------------- /lab2/Debug/link.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab2/Debug/link.write.1.tlog -------------------------------------------------------------------------------- /lab2/Debug/vc110.idb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab2/Debug/vc110.idb -------------------------------------------------------------------------------- /lab2/Debug/vc110.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab2/Debug/vc110.pdb -------------------------------------------------------------------------------- /lab2/Debug/vc120.idb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab2/Debug/vc120.idb -------------------------------------------------------------------------------- /lab2/Debug/vc120.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab2/Debug/vc120.pdb -------------------------------------------------------------------------------- /lab2/lab2-test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | //when you want to test one of the parts of the assignment, just change the 0 into a 1 for 6 | //the constant corresponding to that part 7 | #define COUNT_ONES 1 8 | #define FACTORIAL 1 9 | #define POSITIVE_SUM 1 10 | #define ISPALINDROME 0 11 | 12 | extern char *yourName; 13 | extern char *studentID; 14 | 15 | struct Node{ 16 | int e; 17 | struct Node *next; 18 | }; 19 | 20 | extern unsigned int countOnes(unsigned int x); 21 | extern int factWrapper(int i); 22 | extern int positiveSum(struct Node *head); 23 | extern int isPalindrome(unsigned int x); 24 | 25 | void testOnes(unsigned int x); 26 | void testFactorial(int x); 27 | void testPositiveSum(int *Arr, int len); 28 | struct Node * createList(int * Arr, int len); 29 | void testPalindrome(unsigned int x); 30 | void printName() { 31 | int nameLen = strlen(yourName) + 6; 32 | int idLen = strlen(studentID) + 5; 33 | int width; 34 | if (nameLen >= idLen) 35 | width = nameLen; 36 | else 37 | width = idLen; 38 | printf("+"); 39 | for(int i = 0; i < width; i++) 40 | printf("-"); 41 | printf("+\n"); 42 | 43 | printf("|Name: %s", yourName); 44 | for(int i = 0; i < (width - nameLen); i++) 45 | printf(" "); 46 | printf("|\n"); 47 | 48 | printf("+"); 49 | for(int i = 0; i < width; i++) 50 | printf("-"); 51 | printf("+\n"); 52 | 53 | printf("|ID#: %s", studentID); 54 | for(int i = 0; i < (width - idLen); i++) 55 | printf(" "); 56 | printf("|\n"); 57 | 58 | printf("+"); 59 | for(int i = 0; i < width; i++) 60 | printf("-"); 61 | printf("+\n\n"); 62 | 63 | printf("If you don't see anything, then remember to turn on the \"#define\" flags\nin the beginning of the lab2-test.cpp file.\n"); 64 | } 65 | 66 | void main() { 67 | int i; 68 | printName(); 69 | 70 | #if COUNT_ONES 71 | unsigned int test1[10] = {0, 1, 2, 3, 4, 5, 0x11111111, 0x55555555, 0xAAAAAAAA, 0xFFFFFFFF}; 72 | for (i = 0; i < 10; i++) { 73 | testOnes(test1[i]); 74 | } 75 | #endif 76 | 77 | #if FACTORIAL 78 | for (i = 0; i <= 10; i++) { 79 | testFactorial(i); 80 | } 81 | #endif 82 | 83 | #if POSITIVE_SUM 84 | int Arr[5]; 85 | 86 | Arr[0] = 0; 87 | testPositiveSum(Arr, 1); 88 | 89 | for(i = 0; i < 5; i++) { 90 | Arr[i] = -1; 91 | } 92 | testPositiveSum(Arr, 5); 93 | 94 | for(i = 0; i < 5; i++) { 95 | Arr[i] = 1; 96 | } 97 | testPositiveSum(Arr, 5); 98 | 99 | for(i = 0; i < 5; i++) { 100 | Arr[i] = i * 5 - 10; 101 | } 102 | testPositiveSum(Arr, 5); 103 | #endif 104 | 105 | #if ISPALINDROME 106 | unsigned int test4[10] = {0, 1, 2, 3, 5, 7, 0xA5, 0xAA55, 0xAAAA, 0xFFFFFFFF}; 107 | for (i = 0; i < 10; i++) { 108 | testPalindrome(test4[i]); 109 | } 110 | #endif 111 | } 112 | 113 | #if COUNT_ONES 114 | void testOnes(unsigned int x) { 115 | unsigned count = 0; 116 | unsigned mask = 0x80000000; 117 | unsigned result; 118 | 119 | while (mask > x) { 120 | mask >>= 1; 121 | } 122 | printf("Testing countOnes...\nx="); 123 | while (mask) { 124 | if (x & mask) { 125 | count++; 126 | printf("1"); 127 | } else { 128 | printf("0"); 129 | } 130 | mask >>= 1; 131 | } 132 | 133 | if (x==0) 134 | printf("0"); 135 | printf(". It has %u '1's.\n", count); 136 | 137 | result = countOnes(x); 138 | 139 | if (result == count) 140 | printf("Your result is correct.\n\n"); 141 | else 142 | printf(">>>ERROR<<< Unfortunatly, your result is %u, which is incorrect.\n\n", result); 143 | } 144 | #endif 145 | 146 | #if FACTORIAL 147 | void testFactorial(int x) { 148 | int result; 149 | int correct = 1; 150 | 151 | for (int i = 1; i <= x; i++) { 152 | correct *= i; 153 | } 154 | 155 | printf("Testing factorial of %d...\nThe correct answer is %d.\n", x, correct); 156 | 157 | result = factWrapper(x); 158 | 159 | if (result == correct) 160 | printf("Your result is correct.\n\n"); 161 | else 162 | printf(">>>ERROR<<< Unfortunately, your result is %d, which is incorrect.\n\n", result); 163 | 164 | } 165 | #endif 166 | 167 | #if POSITIVE_SUM 168 | struct Node * createList(int * Arr, int len) { 169 | if (len == 0) { 170 | return NULL; 171 | } 172 | 173 | struct Node *head = (struct Node*)malloc(sizeof(struct Node)); 174 | head->e = Arr[0]; 175 | 176 | struct Node *tail = head; 177 | 178 | for (int i = 1; i < len; i++) { 179 | struct Node *next = (struct Node*)malloc(sizeof(struct Node)); 180 | tail->next = next; 181 | tail = next; 182 | tail->e = Arr[i]; 183 | } 184 | tail->next = NULL; 185 | 186 | return head; 187 | } 188 | 189 | void testPositiveSum(int *Arr, int len) { 190 | struct Node *head = createList(Arr, len); 191 | int correct, result; 192 | struct Node *p = head; 193 | correct = 0; 194 | 195 | printf("Testing positiveSum...\nThe list contains "); 196 | while(p) { 197 | printf("%d, ", p->e); 198 | if (p->e > 0) { 199 | correct += p->e; 200 | } 201 | p = p->next; 202 | } 203 | printf("and the positive sum is %d.\n", correct); 204 | 205 | result = positiveSum(head); 206 | 207 | if (result == correct) 208 | printf("Your result is correct.\n\n"); 209 | else 210 | printf(">>>ERROR<<< Unfortunately, your result is %d, which is incorrect.\n\n", result); 211 | 212 | } 213 | #endif 214 | 215 | #if ISPALINDROME 216 | void testPalindrome(unsigned int x) { 217 | unsigned left=0x80000000, right=1; 218 | int correct, result; 219 | 220 | while(left > x) 221 | left >>= 1; 222 | 223 | printf("Testing isPalindrome...\nx="); 224 | for(unsigned mask = left; mask; mask >>= 1) { 225 | if (x & mask) 226 | printf("1"); 227 | else 228 | printf("0"); 229 | } 230 | if (x==0) 231 | printf("0"); 232 | printf(", "); 233 | 234 | while (left > right) { 235 | if (x & left) { 236 | if ((x & right) == 0) { 237 | break; 238 | } 239 | } else { 240 | if (x & right) { 241 | break; 242 | } 243 | } 244 | left >>= 1; 245 | right <<= 1; 246 | } 247 | 248 | if( left > right ) { 249 | printf("and it is not a palindrome.\n"); 250 | correct = 0; 251 | } else { 252 | printf("and it is a palindrome.\n"); 253 | correct = 1; 254 | } 255 | 256 | result = isPalindrome(x); 257 | 258 | if (result == correct) 259 | printf("Your result is correct.\n\n"); 260 | else 261 | printf(">>>ERROR<<< Unfortunatly, your result is incorrect.\n\n"); 262 | 263 | } 264 | #endif -------------------------------------------------------------------------------- /lab2/lab2.cpp: -------------------------------------------------------------------------------- 1 | /* ICS 51 Lab 2 */ 2 | char * yourName = "Ford Tang"; 3 | char * studentID = "46564602"; 4 | 5 | /******************************************************************************* 6 | Part A - Bit Operation 7 | 8 | Bit operation tends to always come up during interfiews for software engineering 9 | jobs. So I'll give you one to practice with. 10 | 11 | Implement the countOnes function that counts the number of "1"s in the binary 12 | representation of an integer, and returns the result. 13 | 14 | Hint 1. Don't try to convert an integer to binary. All the integers inside your 15 | CPU are in binary already. You should try to think about the "value" of the 16 | integer regardless of its representation. For example, if x = 5, and you move it 17 | into AL, then AL is 00000101 automatically. 18 | 19 | Hint 2. Can you try to move each bit into some flag, and then make a conditional 20 | jump based on that bit? 21 | *******************************************************************************/ 22 | __declspec(naked) unsigned int countOnes(unsigned int x) { 23 | __asm{ 24 | PUSH EBX 25 | PUSH ECX 26 | 27 | MOV EAX, 0 28 | MOV EBX, [ESP + 12] 29 | MOV ECX, 32 30 | 31 | SHIFTLOOP: 32 | SHR EBX, 1 33 | JNC NEXT 34 | ADD EAX, 1 35 | 36 | NEXT: 37 | LOOP SHIFTLOOP 38 | 39 | POP ECX 40 | POP EBX 41 | 42 | RET 43 | } 44 | } 45 | 46 | /******************************************************************************* 47 | Part B - Recursive Function Call 48 | 49 | Implement 2 functions that calculates the factorial of an integer no larger than 50 | 10. (You may assume that the input never gets larger than 10. You don't have to 51 | check.) 52 | 53 | The 1st function, factWrapper(int i), is the non recursive wrapper function 54 | which take the input, sets up the stack, and calls the recursive function. 55 | 56 | The 2nd function, factRec(int x), is the recursive function that actually 57 | calculates the factorial. 58 | 59 | Hint: write your functions in c++/python/java first, then rewrite the code in 60 | assembly. 61 | *******************************************************************************/ 62 | 63 | __declspec(naked) int factRec(int x) { 64 | __asm{ 65 | PUSH EBX 66 | MOV EBX, DWORD PTR[ESP + 8] 67 | CMP EBX, 0 68 | JE EXIT 69 | MUL EBX 70 | SUB EBX, 1 71 | PUSH EBX 72 | CALL factRec 73 | POP EBX 74 | 75 | EXIT: 76 | POP EBX 77 | 78 | ret 79 | } 80 | } 81 | 82 | __declspec(naked) int factWrapper(int i) { 83 | __asm{ 84 | PUSH EBX 85 | 86 | MOV EAX, 1 87 | MOV EBX, [ESP + 8] 88 | 89 | PUSH EBX 90 | 91 | CALL factRec 92 | 93 | POP EBX 94 | 95 | POP EBX 96 | ret 97 | } 98 | } 99 | 100 | /******************************************************************************* 101 | Part C - Linked List Operation 102 | 103 | It is very important to understand how data objects are laid out in memory. 104 | 105 | Recall the positiveSum function in lab 1. We will implement the same function 106 | here again, except that the integers will be stored in a linked list. 107 | *******************************************************************************/ 108 | __declspec(naked) int positiveSum(struct Node *head) { 109 | __asm{ 110 | PUSH EBX 111 | PUSH ECX 112 | MOV EBX, [ESP + 12] 113 | MOV EAX, 0 114 | 115 | TRAVERSE: 116 | MOV ECX, [EBX] 117 | CMP [EBX], 0 118 | JL NEXT 119 | ADD EAX, [EBX] 120 | NEXT: 121 | MOV ECX, [EBX + 4] 122 | CMP ECX, 0 123 | JE END 124 | ADD EBX, 4 125 | MOV EBX, [EBX] 126 | JMP TRAVERSE 127 | 128 | END: 129 | POP ECX 130 | POP EBX 131 | 132 | ret 133 | } 134 | } 135 | 136 | /******************************************************************************* 137 | Part D - Optional Bit Operation 138 | 139 | This is an interview question I encountered at one of the major software 140 | companies. 141 | 142 | Implement isPalindrome(unsigned int x). 143 | 144 | This function checks the binary representation of an unsigned integer and tests 145 | if it is a palindrome. If it is, return 1. otherwise, return 0. 146 | *******************************************************************************/ 147 | __declspec(naked) int isPalindrome(unsigned int x) { 148 | __asm{ 149 | 150 | 151 | ret 152 | } 153 | } -------------------------------------------------------------------------------- /lab2/lab2.sdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab2/lab2.sdf -------------------------------------------------------------------------------- /lab2/lab2.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lab2", "lab2.vcxproj", "{A43950CB-2618-4D0B-ADD6-AF12761D6486}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {A43950CB-2618-4D0B-ADD6-AF12761D6486}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {A43950CB-2618-4D0B-ADD6-AF12761D6486}.Debug|Win32.Build.0 = Debug|Win32 14 | {A43950CB-2618-4D0B-ADD6-AF12761D6486}.Release|Win32.ActiveCfg = Release|Win32 15 | {A43950CB-2618-4D0B-ADD6-AF12761D6486}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /lab2/lab2.v11.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab2/lab2.v11.suo -------------------------------------------------------------------------------- /lab2/lab2.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FordTang/ICS51_IntroductoryComputerOrganization/3e79cb577b61370ed26c03e06a4d81ab6694a2cc/lab2/lab2.v12.suo -------------------------------------------------------------------------------- /lab2/lab2.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | {A43950CB-2618-4D0B-ADD6-AF12761D6486} 19 | Win32Proj 20 | lab2 21 | 22 | 23 | 24 | Application 25 | true 26 | v120 27 | Unicode 28 | 29 | 30 | Application 31 | false 32 | v120 33 | true 34 | Unicode 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | true 48 | 49 | 50 | false 51 | 52 | 53 | 54 | 55 | 56 | Level3 57 | Disabled 58 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 59 | true 60 | 61 | 62 | Console 63 | true 64 | 65 | 66 | 67 | 68 | Level3 69 | 70 | 71 | MaxSpeed 72 | true 73 | true 74 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 75 | true 76 | 77 | 78 | Console 79 | true 80 | true 81 | true 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /lab2/lab2.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | --------------------------------------------------------------------------------